QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#110071#5406. 随机游走vme50100 ✓377ms136788kbC++171.1kb2023-05-31 14:32:582023-05-31 14:32:59

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-31 14:32:59]
  • 评测
  • 测评结果:100
  • 用时:377ms
  • 内存:136788kb
  • [2023-05-31 14:32:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define N 10000005
#define MOD 1000000007
int n,invN,invN1,pw2,ans,fc[N],invFc[N],p[N],pw[N];bool vs[N];
void W(int &x,int y) {x+=y;if(x>=MOD) x-=MOD;}
int qPow(int x,int y)
{
	int res=1;
	for(;y;y/=2,x=1ll*x*x%MOD) if(y&1)
		res=1ll*res*x%MOD;return res;
}
void init(int n)
{
	fc[0]=invFc[0]=1;for(int i=1;i<=n;++i) fc[i]=1ll*fc[i-1]*i%MOD;
	invFc[n]=qPow(fc[n],MOD-2);
	for(int i=n-1;i;--i) invFc[i]=1ll*invFc[i+1]*(i+1)%MOD;
}
void sieve(int n)
{
	vs[1]=pw[1]=1;
	for(int i=2;i<=n;++i)
	{
		if(!vs[i]) p[++p[0]]=i,pw[i]=qPow(i,n);
		for(int j=1;i*p[j]<=n;++j)
		{
			vs[i*p[j]]=1;pw[i*p[j]]=1ll*pw[i]*pw[p[j]]%MOD;
			if(!(i%p[j])) break;
		}
	}
}
int main()
{
	scanf("%d",&n);n*=2;init(n);sieve(n);
	invN=qPow(n,MOD-2);invN1=qPow(n+1,MOD-2);pw2=qPow(2,n);
	for(int i=0,t;i<=n;++i)
	{
		t=(2ll*(n-i)*invN1-1ll*(n-i*2)*invN)%MOD*pw[n-i]%MOD*pw2%MOD;
		if(i*2<n) t=(t+1ll*(invN-invN1)*(n-i*2)%MOD*pw[n-i*2])%MOD;
		t=1ll*(t+MOD)*invFc[i]%MOD*invFc[n-i]%MOD;W(ans,i&1?MOD-t:t);
	}ans=1ll*ans*qPow(pw2,MOD-2)%MOD*n%MOD;printf("%d\n",ans);return 0;
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 9932kb

input:

1

output:

333333336

result:

ok 1 number(s): "333333336"

Test #2:

score: 0
Accepted
time: 0ms
memory: 11788kb

input:

2

output:

266666669

result:

ok 1 number(s): "266666669"

Test #3:

score: 0
Accepted
time: 1ms
memory: 9748kb

input:

3

output:

769047625

result:

ok 1 number(s): "769047625"

Subtask #2:

score: 10
Accepted

Test #4:

score: 10
Accepted
time: 0ms
memory: 9680kb

input:

4

output:

877865968

result:

ok 1 number(s): "877865968"

Test #5:

score: 0
Accepted
time: 1ms
memory: 9920kb

input:

5

output:

733342859

result:

ok 1 number(s): "733342859"

Test #6:

score: 0
Accepted
time: 2ms
memory: 9708kb

input:

6

output:

655899114

result:

ok 1 number(s): "655899114"

Test #7:

score: 0
Accepted
time: 2ms
memory: 9756kb

input:

7

output:

946326757

result:

ok 1 number(s): "946326757"

Test #8:

score: 0
Accepted
time: 4ms
memory: 9744kb

input:

8

output:

230714822

result:

ok 1 number(s): "230714822"

Test #9:

score: 0
Accepted
time: 0ms
memory: 9924kb

input:

9

output:

782967541

result:

ok 1 number(s): "782967541"

Test #10:

score: 0
Accepted
time: 2ms
memory: 9852kb

input:

10

output:

732371611

result:

ok 1 number(s): "732371611"

Subtask #3:

score: 10
Accepted

Test #11:

score: 10
Accepted
time: 4ms
memory: 9684kb

input:

15

output:

677123472

result:

ok 1 number(s): "677123472"

Test #12:

score: 0
Accepted
time: 2ms
memory: 9688kb

input:

13

output:

168974634

result:

ok 1 number(s): "168974634"

Test #13:

score: 0
Accepted
time: 3ms
memory: 9860kb

input:

26

output:

213343876

result:

ok 1 number(s): "213343876"

Test #14:

score: 0
Accepted
time: 4ms
memory: 9740kb

input:

29

output:

631124616

result:

ok 1 number(s): "631124616"

Subtask #4:

score: 15
Accepted

Test #15:

score: 15
Accepted
time: 5ms
memory: 9748kb

input:

37

output:

349256161

result:

ok 1 number(s): "349256161"

Test #16:

score: 0
Accepted
time: 0ms
memory: 9904kb

input:

104

output:

351095881

result:

ok 1 number(s): "351095881"

Test #17:

score: 0
Accepted
time: 3ms
memory: 9756kb

input:

194

output:

895504391

result:

ok 1 number(s): "895504391"

Test #18:

score: 0
Accepted
time: 6ms
memory: 9744kb

input:

197

output:

923555376

result:

ok 1 number(s): "923555376"

Test #19:

score: 0
Accepted
time: 2ms
memory: 9772kb

input:

198

output:

512220517

result:

ok 1 number(s): "512220517"

Subtask #5:

score: 15
Accepted

Test #20:

score: 15
Accepted
time: 2ms
memory: 9740kb

input:

562

output:

255062346

result:

ok 1 number(s): "255062346"

Test #21:

score: 0
Accepted
time: 2ms
memory: 9904kb

input:

1007

output:

735041605

result:

ok 1 number(s): "735041605"

Test #22:

score: 0
Accepted
time: 2ms
memory: 9932kb

input:

1788

output:

208261384

result:

ok 1 number(s): "208261384"

Test #23:

score: 0
Accepted
time: 1ms
memory: 9692kb

input:

1980

output:

875427987

result:

ok 1 number(s): "875427987"

Test #24:

score: 0
Accepted
time: 0ms
memory: 9668kb

input:

1983

output:

571776252

result:

ok 1 number(s): "571776252"

Test #25:

score: 0
Accepted
time: 4ms
memory: 9744kb

input:

1992

output:

12983695

result:

ok 1 number(s): "12983695"

Subtask #6:

score: 15
Accepted

Test #26:

score: 15
Accepted
time: 4ms
memory: 9720kb

input:

3946

output:

977435333

result:

ok 1 number(s): "977435333"

Test #27:

score: 0
Accepted
time: 4ms
memory: 10036kb

input:

65944

output:

312666196

result:

ok 1 number(s): "312666196"

Test #28:

score: 0
Accepted
time: 16ms
memory: 16320kb

input:

163815

output:

163767254

result:

ok 1 number(s): "163767254"

Test #29:

score: 0
Accepted
time: 15ms
memory: 20232kb

input:

198732

output:

911833524

result:

ok 1 number(s): "911833524"

Test #30:

score: 0
Accepted
time: 18ms
memory: 14372kb

input:

199287

output:

910277128

result:

ok 1 number(s): "910277128"

Test #31:

score: 0
Accepted
time: 15ms
memory: 14368kb

input:

199819

output:

561747634

result:

ok 1 number(s): "561747634"

Subtask #7:

score: 30
Accepted

Test #32:

score: 30
Accepted
time: 19ms
memory: 16656kb

input:

315618

output:

602805814

result:

ok 1 number(s): "602805814"

Test #33:

score: 0
Accepted
time: 80ms
memory: 37764kb

input:

1130465

output:

898203793

result:

ok 1 number(s): "898203793"

Test #34:

score: 0
Accepted
time: 336ms
memory: 121804kb

input:

4399723

output:

101317224

result:

ok 1 number(s): "101317224"

Test #35:

score: 0
Accepted
time: 355ms
memory: 132240kb

input:

4804460

output:

114947085

result:

ok 1 number(s): "114947085"

Test #36:

score: 0
Accepted
time: 376ms
memory: 134740kb

input:

4995726

output:

460040939

result:

ok 1 number(s): "460040939"

Test #37:

score: 0
Accepted
time: 377ms
memory: 134732kb

input:

4999919

output:

780785591

result:

ok 1 number(s): "780785591"

Test #38:

score: 0
Accepted
time: 377ms
memory: 136788kb

input:

4999999

output:

742624725

result:

ok 1 number(s): "742624725"