ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#199866 | #177. move | Zxc200611 | 100 | 1167ms | 32452kb | C++11 | 1.1kb | 2023-12-24 08:50:01 | 2023-12-24 12:14:02 |
answer
/*
枚举横边数量,可以任意插入。
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int md=1e9+7;
int ftl[2100000],itl[2100000];
int quickPow(int x,int k)
{
int ans=1;
for(;k;k>>=1,x=x*x%md)
{
if(k&1)
ans=ans*x%md;
}
return ans;
}
void getFactorial(const int lim=2e6+10)
{
ftl[0]=1;
for(int i=1;i<=lim;i++)
ftl[i]=ftl[i-1]*i%md;
itl[lim]=quickPow(ftl[lim],md-2);
for(int i=lim-1;i>=0;i--)
itl[i]=itl[i+1]*(i+1)%md;
}
int C(int n,int m)
{
// cout<<"C "<<n<<" "<<m<<endl;
return n<m?0:(ftl[n]*(itl[m]*itl[n-m]%md)%md);
}
int P(int x,int y)
{
assert((x+y)%2==0);
int a=(x+y)/2,b=(x-y)/2;
// cout<<"P x="<<x<<" y="<<y<<" = C("<<a+b<<","<<b<<")"<<endl;
return C(a+b,b);
}
int solve(int n) // (0,0) -> (n,0)
{
int ans=0;
for(int i=n%2;i<=n;i+=2)
{
ans=(ans+C(n,i)*((P(n-i,0)-P(n-i,-2)+md)%md)%md)%md;
}
return ans;
}
signed main()
{
getFactorial();
int T;
cin>>T;
for(int _=1;_<=T;_++)
{
int n;
cin>>n;
cout<<solve(n)<<'\n';
}
}
/*
3
3
1000
1000000
*/
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 28ms
memory: 32448kb
input:
10 87 126 336 401 396 393 990 967 308 130
output:
952886086 778103891 301307310 497097012 267466056 695715027 490133361 19295392 313508734 87611670
result:
ok 10 lines
Test #2:
score: 5
Accepted
time: 27ms
memory: 32448kb
input:
10 776 458 70 270 555 836 935 748 272 375
output:
692921871 445495094 774348257 379818824 888898709 174497833 196545526 118997364 299113390 299856448
result:
ok 10 lines
Test #3:
score: 5
Accepted
time: 22ms
memory: 32448kb
input:
10 855 340 58 805 522 354 251 543 823 269
output:
615565992 819883319 298217690 69689203 884819632 264378106 122305893 483673609 538195482 765591101
result:
ok 10 lines
Test #4:
score: 5
Accepted
time: 21ms
memory: 32452kb
input:
10 861 814 845 431 88 290 723 925 653 987
output:
66379951 218730106 646412481 779603910 934817196 549036495 938207208 515670413 187358499 885002046
result:
ok 10 lines
Test #5:
score: 5
Accepted
time: 21ms
memory: 32452kb
input:
10 5139 6360 6177 3920 1126 9257 5310 927 1028 723
output:
53992314 779209990 272656703 726194903 575528693 99668723 175131710 16492713 58158406 938207208
result:
ok 10 lines
Test #6:
score: 5
Accepted
time: 14ms
memory: 32448kb
input:
10 421 6323 1406 4271 9545 241 9785 6155 8416 8625
output:
504938765 241955822 418503361 879313548 600795516 401159863 845118197 688275255 813359771 170747506
result:
ok 10 lines
Test #7:
score: 5
Accepted
time: 20ms
memory: 32448kb
input:
10 1623 7654 2419 5220 7788 6086 4514 878 8719 889
output:
985056431 366520371 610623700 79873919 152612466 564409096 826125318 108992217 884889426 299052566
result:
ok 10 lines
Test #8:
score: 5
Accepted
time: 15ms
memory: 32448kb
input:
10 4834 9049 5788 5053 2368 678 7019 8699 6095 9771
output:
894248955 48762405 157733240 975780451 870697369 618636072 8225406 846511000 723654845 466048177
result:
ok 10 lines
Test #9:
score: 5
Accepted
time: 28ms
memory: 32452kb
input:
10 9992 9411 7282 2934 2901 2668 6567 4524 4102 8524
output:
75603159 139639091 827313831 749841764 833868754 310259549 804778809 416380457 20118359 546399661
result:
ok 10 lines
Test #10:
score: 5
Accepted
time: 18ms
memory: 32448kb
input:
10 9520 2862 3208 7053 9602 2486 9472 8500 3375 6827
output:
168898108 549139767 780176643 823630021 91024868 918528824 298818369 236242005 173037285 224016415
result:
ok 10 lines
Test #11:
score: 5
Accepted
time: 104ms
memory: 32452kb
input:
10 59737 856616 467799 850140 940542 645886 381456 829699 317966 558490
output:
839529689 148943889 832435699 656537703 309790708 896597601 884248120 847282933 610220680 17852453
result:
ok 10 lines
Test #12:
score: 5
Accepted
time: 79ms
memory: 32448kb
input:
10 836166 344091 589267 224275 743829 124824 37191 619801 314432 25360
output:
363572876 802728099 713874676 652189567 833071556 653110228 600371759 443480105 341963835 459920462
result:
ok 10 lines
Test #13:
score: 5
Accepted
time: 72ms
memory: 32452kb
input:
10 619868 45579 115131 121441 523910 321297 324365 602432 805322 490275
output:
528209934 480081255 386752639 15197841 617475320 8989877 616139785 763612257 554465540 480653058
result:
ok 10 lines
Test #14:
score: 5
Accepted
time: 115ms
memory: 32452kb
input:
10 552883 123886 867678 885767 850366 997032 984348 337236 233611 175426
output:
910799573 555873268 275513814 647312715 798769572 133859592 837931577 653969046 453890146 433794677
result:
ok 10 lines
Test #15:
score: 5
Accepted
time: 105ms
memory: 32448kb
input:
10 395505 432537 433480 262843 655874 343802 741245 868350 317808 682914
output:
781690159 128762586 44286220 902962745 242841990 280305487 885695030 246608547 143918021 262112863
result:
ok 10 lines
Test #16:
score: 5
Accepted
time: 98ms
memory: 32452kb
input:
10 63349 886119 176835 613938 308562 578253 594380 699798 689504 617810
output:
583981305 176628003 564919936 576538515 775560152 143079589 563319325 834895660 585267643 507384150
result:
ok 10 lines
Test #17:
score: 5
Accepted
time: 86ms
memory: 32452kb
input:
10 346593 166648 733852 27658 749332 551494 306467 928849 204793 778283
output:
772457634 24388769 933904578 513219933 329059863 109045106 455847970 560314790 989158553 189795809
result:
ok 10 lines
Test #18:
score: 5
Accepted
time: 97ms
memory: 32452kb
input:
10 756444 771536 854707 86019 86784 666644 755548 534218 82420 950867
output:
371708117 254410932 897168639 296496017 532423155 174791785 399453127 566608229 764210643 276037323
result:
ok 10 lines
Test #19:
score: 5
Accepted
time: 83ms
memory: 32448kb
input:
10 803327 236316 216530 558863 957651 635525 773678 28658 600968 485504
output:
783030543 907156811 592914588 488077290 398405119 265899907 552853838 178755889 861447556 422291694
result:
ok 10 lines
Test #20:
score: 5
Accepted
time: 114ms
memory: 32452kb
input:
10 836166 344091 589267 224275 743829 124824 37191 619801 314432 25360
output:
363572876 802728099 713874676 652189567 833071556 653110228 600371759 443480105 341963835 459920462
result:
ok 10 lines