QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#384379#6748. Spin the WheelfzxWA 900ms12328kbC++141.3kb2024-04-09 22:29:292024-04-09 22:29:30

Judging History

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

  • [2024-04-09 22:29:30]
  • 评测
  • 测评结果:WA
  • 用时:900ms
  • 内存:12328kb
  • [2024-04-09 22:29:29]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long 
using namespace std;
mt19937 rnd(chrono::system_clock().now().time_since_epoch().count());
int gen(int l,int r) {return rnd()%(r-l+1)+l;}
const int INF=2e5+5;
int n,a[INF],b[INF],cc[INF],ba2[INF],pp[INF],vis[INF];
int ksm(int x,int y,int Mod) {
	int ba=x%Mod,ans=1;
	while (y) {
		if (y&1) ans=(ans*ba)%Mod;
		ba=(ba*ba)%Mod;y>>=1;
	}
	return ans;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i]; 
	int res=1e18,fl=0;;
	for (int i=0;i<n;i++) 
		if (i*a[1]%n!=a[i]) fl=1;
	if (!fl) res=min(res,a[1]);
	for (int i=0;i<n;i++) b[i]=a[i]-i,b[i]%=n,b[i]+=n,b[i]%=n;
	for (int i=0;i<=n;i++) b[i+n]=b[i];
	
	for (int y=1;y<n;y++) vis[y]=1;
	for (int T=1;T<=200;T++) {
		int ba=gen(1,200),sum=0;
		for (int i=0;i<n;i++) pp[i]=gen(1,1e9);
		for (int i=0;i<n;i++) sum=(sum*ba+pp[i])%n;
		for (int i=0;i<=n+n;i++) cc[i]=(cc[i-1]*ba+pp[b[i]])%n;
		ba2[0]=1;
		for (int i=1;i<=n+n;i++) ba2[i]=ba2[i-1]*ba%n;
		int Mod=n;
		for (int y=1;y<n;y++) {
			if (b[1+y]*sum%Mod!=((cc[n-1+y]-cc[0+y-1]*ba2[n])%Mod+Mod)%Mod) vis[y]=0;
		}
	}	
	for (int y=1;y<n;y++)
		if (vis[y]) {
			res=min(res,b[1+y]+2);
		}
	if (res>1e9) cout<<"-1\n";
	else cout<<res<<"\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7832kb

input:

5
1 3 0 2 4

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 894ms
memory: 12208kb

input:

100000
0 55555 11110 66665 22220 77775 33330 88885 44440 99995 55550 11105 66660 22215 77770 33325 88880 44435 99990 55545 11100 66655 22210 77765 33320 88875 44430 99985 55540 11095 66650 22205 77760 33315 88870 44425 99980 55535 11090 66645 22200 77755 33310 88865 44420 99975 55530 11085 66640 221...

output:

55555

result:

ok 1 number(s): "55555"

Test #3:

score: 0
Accepted
time: 898ms
memory: 12328kb

input:

100000
0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 50000 0 500...

output:

50000

result:

ok 1 number(s): "50000"

Test #4:

score: -100
Wrong Answer
time: 900ms
memory: 12260kb

input:

100000
1 401 801 1201 1601 2001 2401 2801 3201 3601 4001 4401 4801 5201 5601 6001 6401 6801 7201 7601 8001 8401 8801 9201 9601 10001 10401 10801 11201 11601 12001 12401 12801 13201 13601 14001 14401 14801 15201 15601 16001 16401 16801 17201 17601 18001 18401 18801 19201 19601 20001 20401 20801 21201...

output:

-1

result:

wrong answer 1st numbers differ - expected: '401', found: '-1'