QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227112 | #5406. 随机游走 | zhouhuanyi | 70 | 837ms | 160072kb | C++23 | 1.4kb | 2023-10-26 22:35:03 | 2023-10-26 22:35:03 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 20000000
#define mod 1000000007
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int MD(int x)
{
return x>=mod?x-mod:x;
}
int MD2(int x)
{
return x<0?x+mod:x;
}
void Adder(int &x,int d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
void Adder2(int &x,int d)
{
x+=d;
if (x<0) x+=mod;
return;
}
int n,ans,fac[N+1],invfac[N+1];
int fast_pow(int a,int b)
{
int res=1,mul=a;
while (b)
{
if (b&1) res=1ll*res*mul%mod;
mul=1ll*mul*mul%mod,b>>=1;
}
return res;
}
int C(int x,int y)
{
if (x<y) return 0;
return 1ll*fac[x]*invfac[y]%mod*invfac[x-y]%mod;
}
int calc(int x)
{
return 1ll*fast_pow(x,n<<1)*invfac[n<<1]%mod;
}
int calc2(int x)
{
return 1ll*fast_pow(x,(n<<1)+1)*MD2(invfac[n<<1]-invfac[(n<<1)+1])%mod;
}
int main()
{
int l;
fac[0]=1;
for (int i=1;i<=N;++i) fac[i]=1ll*fac[i-1]*i%mod;
invfac[N]=fast_pow(fac[N],mod-2);
for (int i=N-1;i>=0;--i) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
n=read();
for (int i=0;i<=(n<<1);++i)
{
l=max(n-i,0);
if (!(i&1)) Adder(ans,1ll*C(n<<1,i)*MD2(MD2(calc2((n<<1)-i)-calc2(l))-1ll*MD2(calc((n<<1)-i)-calc(l))*MD2(n-i)%mod)%mod);
else Adder2(ans,-1ll*C(n<<1,i)*MD2(MD2(calc2((n<<1)-i)-calc2(l))-1ll*MD2(calc((n<<1)-i)-calc(l))*MD2(n-i)%mod)%mod);
}
printf("%lld\n",2ll*ans%mod);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 160ms
memory: 159780kb
input:
1
output:
333333336
result:
ok 1 number(s): "333333336"
Test #2:
score: 0
Accepted
time: 192ms
memory: 159788kb
input:
2
output:
266666669
result:
ok 1 number(s): "266666669"
Test #3:
score: 0
Accepted
time: 150ms
memory: 160020kb
input:
3
output:
769047625
result:
ok 1 number(s): "769047625"
Subtask #2:
score: 10
Accepted
Test #4:
score: 10
Accepted
time: 139ms
memory: 159972kb
input:
4
output:
877865968
result:
ok 1 number(s): "877865968"
Test #5:
score: 0
Accepted
time: 153ms
memory: 159844kb
input:
5
output:
733342859
result:
ok 1 number(s): "733342859"
Test #6:
score: 0
Accepted
time: 205ms
memory: 159840kb
input:
6
output:
655899114
result:
ok 1 number(s): "655899114"
Test #7:
score: 0
Accepted
time: 175ms
memory: 160004kb
input:
7
output:
946326757
result:
ok 1 number(s): "946326757"
Test #8:
score: 0
Accepted
time: 187ms
memory: 159844kb
input:
8
output:
230714822
result:
ok 1 number(s): "230714822"
Test #9:
score: 0
Accepted
time: 143ms
memory: 160072kb
input:
9
output:
782967541
result:
ok 1 number(s): "782967541"
Test #10:
score: 0
Accepted
time: 163ms
memory: 159744kb
input:
10
output:
732371611
result:
ok 1 number(s): "732371611"
Subtask #3:
score: 10
Accepted
Test #11:
score: 10
Accepted
time: 174ms
memory: 160000kb
input:
15
output:
677123472
result:
ok 1 number(s): "677123472"
Test #12:
score: 0
Accepted
time: 195ms
memory: 159864kb
input:
13
output:
168974634
result:
ok 1 number(s): "168974634"
Test #13:
score: 0
Accepted
time: 172ms
memory: 159836kb
input:
26
output:
213343876
result:
ok 1 number(s): "213343876"
Test #14:
score: 0
Accepted
time: 191ms
memory: 159716kb
input:
29
output:
631124616
result:
ok 1 number(s): "631124616"
Subtask #4:
score: 15
Accepted
Test #15:
score: 15
Accepted
time: 171ms
memory: 159840kb
input:
37
output:
349256161
result:
ok 1 number(s): "349256161"
Test #16:
score: 0
Accepted
time: 167ms
memory: 159964kb
input:
104
output:
351095881
result:
ok 1 number(s): "351095881"
Test #17:
score: 0
Accepted
time: 167ms
memory: 159716kb
input:
194
output:
895504391
result:
ok 1 number(s): "895504391"
Test #18:
score: 0
Accepted
time: 189ms
memory: 159840kb
input:
197
output:
923555376
result:
ok 1 number(s): "923555376"
Test #19:
score: 0
Accepted
time: 187ms
memory: 159712kb
input:
198
output:
512220517
result:
ok 1 number(s): "512220517"
Subtask #5:
score: 15
Accepted
Test #20:
score: 15
Accepted
time: 163ms
memory: 159844kb
input:
562
output:
255062346
result:
ok 1 number(s): "255062346"
Test #21:
score: 0
Accepted
time: 192ms
memory: 159792kb
input:
1007
output:
735041605
result:
ok 1 number(s): "735041605"
Test #22:
score: 0
Accepted
time: 184ms
memory: 160072kb
input:
1788
output:
208261384
result:
ok 1 number(s): "208261384"
Test #23:
score: 0
Accepted
time: 179ms
memory: 159712kb
input:
1980
output:
875427987
result:
ok 1 number(s): "875427987"
Test #24:
score: 0
Accepted
time: 184ms
memory: 159792kb
input:
1983
output:
571776252
result:
ok 1 number(s): "571776252"
Test #25:
score: 0
Accepted
time: 183ms
memory: 159716kb
input:
1992
output:
12983695
result:
ok 1 number(s): "12983695"
Subtask #6:
score: 15
Accepted
Test #26:
score: 15
Accepted
time: 181ms
memory: 159780kb
input:
3946
output:
977435333
result:
ok 1 number(s): "977435333"
Test #27:
score: 0
Accepted
time: 223ms
memory: 159964kb
input:
65944
output:
312666196
result:
ok 1 number(s): "312666196"
Test #28:
score: 0
Accepted
time: 271ms
memory: 159972kb
input:
163815
output:
163767254
result:
ok 1 number(s): "163767254"
Test #29:
score: 0
Accepted
time: 258ms
memory: 159784kb
input:
198732
output:
911833524
result:
ok 1 number(s): "911833524"
Test #30:
score: 0
Accepted
time: 261ms
memory: 160024kb
input:
199287
output:
910277128
result:
ok 1 number(s): "910277128"
Test #31:
score: 0
Accepted
time: 284ms
memory: 159716kb
input:
199819
output:
561747634
result:
ok 1 number(s): "561747634"
Subtask #7:
score: 0
Time Limit Exceeded
Test #32:
score: 30
Accepted
time: 293ms
memory: 159836kb
input:
315618
output:
602805814
result:
ok 1 number(s): "602805814"
Test #33:
score: 0
Accepted
time: 837ms
memory: 159784kb
input:
1130465
output:
898203793
result:
ok 1 number(s): "898203793"
Test #34:
score: -30
Time Limit Exceeded
input:
4399723