QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#82344 | #5406. 随机游走 | zhouhuanyi | 0 | 239ms | 238116kb | C++23 | 1.2kb | 2023-02-27 16:20:36 | 2023-02-27 16:20:37 |
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 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;
}
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],inv[N+1];
int C(int x,int y)
{
if (x<y) return 0;
return 1ll*fac[x]*invfac[y]%mod*invfac[x-y]%mod;
}
int main()
{
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;
for (int i=1;i<=N;++i) inv[i]=1ll*fac[i-1]*invfac[i]%mod;
n=read(),ans=1;
for (int i=0;i<=n;++i)
{
if (!(i&1)) Adder2(ans,-1ll*C(n,i)*inv[(i<<1)+1]%mod);
else Adder(ans,1ll*C(n,i)*inv[(i<<1)+1]%mod);
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 209ms
memory: 237888kb
input:
1
output:
333333336
result:
ok 1 number(s): "333333336"
Test #2:
score: 0
Accepted
time: 233ms
memory: 237844kb
input:
2
output:
266666669
result:
ok 1 number(s): "266666669"
Test #3:
score: -5
Wrong Answer
time: 214ms
memory: 238112kb
input:
3
output:
942857150
result:
wrong answer 1st numbers differ - expected: '769047625', found: '942857150'
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 233ms
memory: 237908kb
input:
4
output:
393650797
result:
wrong answer 1st numbers differ - expected: '877865968', found: '393650797'
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 236ms
memory: 237844kb
input:
15
output:
571674925
result:
wrong answer 1st numbers differ - expected: '677123472', found: '571674925'
Subtask #4:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 239ms
memory: 238116kb
input:
37
output:
917610801
result:
wrong answer 1st numbers differ - expected: '349256161', found: '917610801'
Subtask #5:
score: 0
Wrong Answer
Test #20:
score: 0
Wrong Answer
time: 193ms
memory: 237900kb
input:
562
output:
993027929
result:
wrong answer 1st numbers differ - expected: '255062346', found: '993027929'
Subtask #6:
score: 0
Wrong Answer
Test #26:
score: 0
Wrong Answer
time: 212ms
memory: 237900kb
input:
3946
output:
692327942
result:
wrong answer 1st numbers differ - expected: '977435333', found: '692327942'
Subtask #7:
score: 0
Wrong Answer
Test #32:
score: 0
Wrong Answer
time: 221ms
memory: 238032kb
input:
315618
output:
2044765
result:
wrong answer 1st numbers differ - expected: '602805814', found: '2044765'