QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#80207 | #5406. 随机游走 | tricyzhkx | 100 ✓ | 554ms | 340316kb | C++14 | 1.2kb | 2023-02-23 08:42:49 | 2023-02-23 08:42:50 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7,_2=(mod+1)/2;
typedef long long ll;
int n,prime[2000010],tot;
bool nopri[20000010];
ll iv1,iv2,pw[20000010],fac[10000010],inv[10000010];
ll C(int n,int m){return fac[n]*inv[n-m]%mod*inv[m]%mod;}
ll power(ll a,int b)
{
ll ans=1;
for(;b;b>>=1,a=a*a%mod)
if(b&1) ans=ans*a%mod;
return ans;
}
ll calc(int m,int a)// \int_0^m x^{2*n-1}(x-a) dx
{
return (m*iv2+(mod-a)*iv1)%mod*pw[m]%mod;
}
int main()
{
int ans=0;
cin>>n;
fac[0]=fac[1]=inv[0]=inv[1]=1;
for(int i=2;i<=2*n+1;i++) fac[i]=fac[i-1]*i%mod;
inv[2*n+1]=power(fac[2*n+1],mod-2);
for(int i=2*n+1;i>=2;i--) inv[i-1]=inv[i]*i%mod;
nopri[0]=nopri[1]=1;pw[1]=1;
for(int i=2;i<=4*n;i++)
{
if(!nopri[i]) prime[++tot]=i,pw[i]=power(i,2*n);
for(int j=1;j<=tot && i*prime[j]<=4*n;j++)
{
nopri[i*prime[j]]=1;
pw[i*prime[j]]=pw[i]*pw[prime[j]]%mod;
if(i%prime[j]==0) break;
}
}
iv1=power(2*n,mod-2);iv2=power(2*n+1,mod-2);
ll w=inv[2*n-1]*power(_2,2*n+1)%mod;
for(int i=0;i<=2*n;i++)
{
ll t1=calc(max(0,2*n-2*i),2*n-2*i),t2=calc(4*n-2*i,2*n-2*i);
ans=(ans+(i&1?mod-C(2*n,i):C(2*n,i))*(t2-2*t1+2*mod))%mod;
}
cout<<(ll)ans*w%mod<<endl;
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 2ms
memory: 3272kb
input:
1
output:
333333336
result:
ok 1 number(s): "333333336"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3520kb
input:
2
output:
266666669
result:
ok 1 number(s): "266666669"
Test #3:
score: 0
Accepted
time: 2ms
memory: 3376kb
input:
3
output:
769047625
result:
ok 1 number(s): "769047625"
Subtask #2:
score: 10
Accepted
Test #4:
score: 10
Accepted
time: 1ms
memory: 3396kb
input:
4
output:
877865968
result:
ok 1 number(s): "877865968"
Test #5:
score: 0
Accepted
time: 2ms
memory: 3416kb
input:
5
output:
733342859
result:
ok 1 number(s): "733342859"
Test #6:
score: 0
Accepted
time: 2ms
memory: 3368kb
input:
6
output:
655899114
result:
ok 1 number(s): "655899114"
Test #7:
score: 0
Accepted
time: 2ms
memory: 3376kb
input:
7
output:
946326757
result:
ok 1 number(s): "946326757"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3348kb
input:
8
output:
230714822
result:
ok 1 number(s): "230714822"
Test #9:
score: 0
Accepted
time: 2ms
memory: 3396kb
input:
9
output:
782967541
result:
ok 1 number(s): "782967541"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3344kb
input:
10
output:
732371611
result:
ok 1 number(s): "732371611"
Subtask #3:
score: 10
Accepted
Test #11:
score: 10
Accepted
time: 0ms
memory: 3416kb
input:
15
output:
677123472
result:
ok 1 number(s): "677123472"
Test #12:
score: 0
Accepted
time: 2ms
memory: 3316kb
input:
13
output:
168974634
result:
ok 1 number(s): "168974634"
Test #13:
score: 0
Accepted
time: 2ms
memory: 3316kb
input:
26
output:
213343876
result:
ok 1 number(s): "213343876"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3372kb
input:
29
output:
631124616
result:
ok 1 number(s): "631124616"
Subtask #4:
score: 15
Accepted
Test #15:
score: 15
Accepted
time: 1ms
memory: 3376kb
input:
37
output:
349256161
result:
ok 1 number(s): "349256161"
Test #16:
score: 0
Accepted
time: 3ms
memory: 3412kb
input:
104
output:
351095881
result:
ok 1 number(s): "351095881"
Test #17:
score: 0
Accepted
time: 2ms
memory: 3376kb
input:
194
output:
895504391
result:
ok 1 number(s): "895504391"
Test #18:
score: 0
Accepted
time: 2ms
memory: 3400kb
input:
197
output:
923555376
result:
ok 1 number(s): "923555376"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3380kb
input:
198
output:
512220517
result:
ok 1 number(s): "512220517"
Subtask #5:
score: 15
Accepted
Test #20:
score: 15
Accepted
time: 0ms
memory: 3400kb
input:
562
output:
255062346
result:
ok 1 number(s): "255062346"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3428kb
input:
1007
output:
735041605
result:
ok 1 number(s): "735041605"
Test #22:
score: 0
Accepted
time: 3ms
memory: 3452kb
input:
1788
output:
208261384
result:
ok 1 number(s): "208261384"
Test #23:
score: 0
Accepted
time: 2ms
memory: 3524kb
input:
1980
output:
875427987
result:
ok 1 number(s): "875427987"
Test #24:
score: 0
Accepted
time: 2ms
memory: 3676kb
input:
1983
output:
571776252
result:
ok 1 number(s): "571776252"
Test #25:
score: 0
Accepted
time: 1ms
memory: 3480kb
input:
1992
output:
12983695
result:
ok 1 number(s): "12983695"
Subtask #6:
score: 15
Accepted
Test #26:
score: 15
Accepted
time: 2ms
memory: 3660kb
input:
3946
output:
977435333
result:
ok 1 number(s): "977435333"
Test #27:
score: 0
Accepted
time: 10ms
memory: 7972kb
input:
65944
output:
312666196
result:
ok 1 number(s): "312666196"
Test #28:
score: 0
Accepted
time: 19ms
memory: 14568kb
input:
163815
output:
163767254
result:
ok 1 number(s): "163767254"
Test #29:
score: 0
Accepted
time: 17ms
memory: 16992kb
input:
198732
output:
911833524
result:
ok 1 number(s): "911833524"
Test #30:
score: 0
Accepted
time: 17ms
memory: 16820kb
input:
199287
output:
910277128
result:
ok 1 number(s): "910277128"
Test #31:
score: 0
Accepted
time: 15ms
memory: 16884kb
input:
199819
output:
561747634
result:
ok 1 number(s): "561747634"
Subtask #7:
score: 30
Accepted
Test #32:
score: 30
Accepted
time: 29ms
memory: 24732kb
input:
315618
output:
602805814
result:
ok 1 number(s): "602805814"
Test #33:
score: 0
Accepted
time: 97ms
memory: 79696kb
input:
1130465
output:
898203793
result:
ok 1 number(s): "898203793"
Test #34:
score: 0
Accepted
time: 504ms
memory: 299912kb
input:
4399723
output:
101317224
result:
ok 1 number(s): "101317224"
Test #35:
score: 0
Accepted
time: 554ms
memory: 327368kb
input:
4804460
output:
114947085
result:
ok 1 number(s): "114947085"
Test #36:
score: 0
Accepted
time: 542ms
memory: 340060kb
input:
4995726
output:
460040939
result:
ok 1 number(s): "460040939"
Test #37:
score: 0
Accepted
time: 553ms
memory: 340244kb
input:
4999919
output:
780785591
result:
ok 1 number(s): "780785591"
Test #38:
score: 0
Accepted
time: 517ms
memory: 340316kb
input:
4999999
output:
742624725
result:
ok 1 number(s): "742624725"