QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#82338 | #5406. 随机游走 | zhouhuanyi | 0 | 250ms | 238116kb | C++23 | 1.2kb | 2023-02-27 16:13:30 | 2023-02-27 16:13:31 |
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) 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;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 250ms
memory: 238116kb
input:
1
output:
333333336
result:
ok 1 number(s): "333333336"
Test #2:
score: -5
Wrong Answer
time: 194ms
memory: 237844kb
input:
2
output:
66666668
result:
wrong answer 1st numbers differ - expected: '266666669', found: '66666668'
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 219ms
memory: 238060kb
input:
4
output:
415873022
result:
wrong answer 1st numbers differ - expected: '877865968', found: '415873022'
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 209ms
memory: 237900kb
input:
15
output:
816572322
result:
wrong answer 1st numbers differ - expected: '677123472', found: '816572322'
Subtask #4:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 225ms
memory: 237736kb
input:
37
output:
545173688
result:
wrong answer 1st numbers differ - expected: '349256161', found: '545173688'
Subtask #5:
score: 0
Wrong Answer
Test #20:
score: 0
Wrong Answer
time: 230ms
memory: 237904kb
input:
562
output:
698702328
result:
wrong answer 1st numbers differ - expected: '255062346', found: '698702328'
Subtask #6:
score: 0
Wrong Answer
Test #26:
score: 0
Wrong Answer
time: 236ms
memory: 237876kb
input:
3946
output:
847307879
result:
wrong answer 1st numbers differ - expected: '977435333', found: '847307879'
Subtask #7:
score: 0
Wrong Answer
Test #32:
score: 0
Wrong Answer
time: 236ms
memory: 237848kb
input:
315618
output:
574587928
result:
wrong answer 1st numbers differ - expected: '602805814', found: '574587928'