QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#398369 | #5406. 随机游走 | le0n | 100 ✓ | 639ms | 82076kb | C++14 | 825b | 2024-04-25 11:13:19 | 2024-04-25 11:13:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int fac[10000005], inv[10000005];
int qpow(int x, int y)
{
int ans = 1;
while(y)
{
if(y & 1)
ans = (ll)ans * x % mod;
x = (ll)x * x % mod;
y >>= 1;
}
return ans;
}
int main()
{
int n, i, r, ans = 0, tmp;
scanf("%d", &n);
fac[0] = 1;
for(i = 1; i <= 2 * n; i++)
fac[i] = (ll)fac[i - 1] * i % mod;
inv[2 * n] = qpow(fac[2 * n], mod - 2);
for(i = 2 * n; i >= 1; i--)
inv[i - 1] = (ll)inv[i] * i % mod;
r = qpow(2 * n + 1, mod - 2);
for(i = 0; i <= n; i++)
{
tmp = (ll)inv[i] * inv[2 * n - i] % mod * r % mod * qpow(n - i, 2 * n + 1) % mod;
if(i & 1)
tmp = mod - tmp;
ans = (ans + tmp) % mod;
}
ans = (ll)ans * 2 % mod;
printf("%d\n", ans);
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 1ms
memory: 3916kb
input:
1
output:
333333336
result:
ok 1 number(s): "333333336"
Test #2:
score: 5
Accepted
time: 1ms
memory: 3916kb
input:
2
output:
266666669
result:
ok 1 number(s): "266666669"
Test #3:
score: 5
Accepted
time: 1ms
memory: 3776kb
input:
3
output:
769047625
result:
ok 1 number(s): "769047625"
Subtask #2:
score: 10
Accepted
Test #4:
score: 10
Accepted
time: 0ms
memory: 3768kb
input:
4
output:
877865968
result:
ok 1 number(s): "877865968"
Test #5:
score: 10
Accepted
time: 0ms
memory: 3776kb
input:
5
output:
733342859
result:
ok 1 number(s): "733342859"
Test #6:
score: 10
Accepted
time: 0ms
memory: 3960kb
input:
6
output:
655899114
result:
ok 1 number(s): "655899114"
Test #7:
score: 10
Accepted
time: 1ms
memory: 3892kb
input:
7
output:
946326757
result:
ok 1 number(s): "946326757"
Test #8:
score: 10
Accepted
time: 0ms
memory: 3828kb
input:
8
output:
230714822
result:
ok 1 number(s): "230714822"
Test #9:
score: 10
Accepted
time: 0ms
memory: 3768kb
input:
9
output:
782967541
result:
ok 1 number(s): "782967541"
Test #10:
score: 10
Accepted
time: 0ms
memory: 3912kb
input:
10
output:
732371611
result:
ok 1 number(s): "732371611"
Subtask #3:
score: 10
Accepted
Test #11:
score: 10
Accepted
time: 0ms
memory: 3776kb
input:
15
output:
677123472
result:
ok 1 number(s): "677123472"
Test #12:
score: 10
Accepted
time: 1ms
memory: 3828kb
input:
13
output:
168974634
result:
ok 1 number(s): "168974634"
Test #13:
score: 10
Accepted
time: 0ms
memory: 3912kb
input:
26
output:
213343876
result:
ok 1 number(s): "213343876"
Test #14:
score: 10
Accepted
time: 0ms
memory: 3952kb
input:
29
output:
631124616
result:
ok 1 number(s): "631124616"
Subtask #4:
score: 15
Accepted
Test #15:
score: 15
Accepted
time: 0ms
memory: 3892kb
input:
37
output:
349256161
result:
ok 1 number(s): "349256161"
Test #16:
score: 15
Accepted
time: 0ms
memory: 3832kb
input:
104
output:
351095881
result:
ok 1 number(s): "351095881"
Test #17:
score: 15
Accepted
time: 0ms
memory: 3904kb
input:
194
output:
895504391
result:
ok 1 number(s): "895504391"
Test #18:
score: 15
Accepted
time: 0ms
memory: 3920kb
input:
197
output:
923555376
result:
ok 1 number(s): "923555376"
Test #19:
score: 15
Accepted
time: 0ms
memory: 3968kb
input:
198
output:
512220517
result:
ok 1 number(s): "512220517"
Subtask #5:
score: 15
Accepted
Test #20:
score: 15
Accepted
time: 0ms
memory: 3924kb
input:
562
output:
255062346
result:
ok 1 number(s): "255062346"
Test #21:
score: 15
Accepted
time: 1ms
memory: 3920kb
input:
1007
output:
735041605
result:
ok 1 number(s): "735041605"
Test #22:
score: 15
Accepted
time: 1ms
memory: 3944kb
input:
1788
output:
208261384
result:
ok 1 number(s): "208261384"
Test #23:
score: 15
Accepted
time: 1ms
memory: 3908kb
input:
1980
output:
875427987
result:
ok 1 number(s): "875427987"
Test #24:
score: 15
Accepted
time: 1ms
memory: 3940kb
input:
1983
output:
571776252
result:
ok 1 number(s): "571776252"
Test #25:
score: 15
Accepted
time: 0ms
memory: 3984kb
input:
1992
output:
12983695
result:
ok 1 number(s): "12983695"
Subtask #6:
score: 15
Accepted
Test #26:
score: 15
Accepted
time: 1ms
memory: 3956kb
input:
3946
output:
977435333
result:
ok 1 number(s): "977435333"
Test #27:
score: 15
Accepted
time: 7ms
memory: 4800kb
input:
65944
output:
312666196
result:
ok 1 number(s): "312666196"
Test #28:
score: 15
Accepted
time: 15ms
memory: 6472kb
input:
163815
output:
163767254
result:
ok 1 number(s): "163767254"
Test #29:
score: 15
Accepted
time: 22ms
memory: 7060kb
input:
198732
output:
911833524
result:
ok 1 number(s): "911833524"
Test #30:
score: 15
Accepted
time: 22ms
memory: 7008kb
input:
199287
output:
910277128
result:
ok 1 number(s): "910277128"
Test #31:
score: 15
Accepted
time: 23ms
memory: 7072kb
input:
199819
output:
561747634
result:
ok 1 number(s): "561747634"
Subtask #7:
score: 30
Accepted
Test #32:
score: 30
Accepted
time: 36ms
memory: 8748kb
input:
315618
output:
602805814
result:
ok 1 number(s): "602805814"
Test #33:
score: 30
Accepted
time: 134ms
memory: 21624kb
input:
1130465
output:
898203793
result:
ok 1 number(s): "898203793"
Test #34:
score: 30
Accepted
time: 536ms
memory: 73080kb
input:
4399723
output:
101317224
result:
ok 1 number(s): "101317224"
Test #35:
score: 30
Accepted
time: 611ms
memory: 80448kb
input:
4804460
output:
114947085
result:
ok 1 number(s): "114947085"
Test #36:
score: 30
Accepted
time: 633ms
memory: 81996kb
input:
4995726
output:
460040939
result:
ok 1 number(s): "460040939"
Test #37:
score: 30
Accepted
time: 636ms
memory: 82076kb
input:
4999919
output:
780785591
result:
ok 1 number(s): "780785591"
Test #38:
score: 30
Accepted
time: 639ms
memory: 82040kb
input:
4999999
output:
742624725
result:
ok 1 number(s): "742624725"