QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#384337 | #6748. Spin the Wheel | fzx | WA | 1ms | 7820kb | C++14 | 1.0kb | 2024-04-09 22:08:40 | 2024-04-09 22:08:40 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF=2e5+5;
int n,a[INF],b[INF],cc[INF],ba2[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];
int ba=191,sum=0;
for (int i=0;i<n;i++) sum=(sum*ba+i)%n;
for (int i=0;i<n+n;i++) cc[i]=(cc[i-1]*ba+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++) {
// int fl=0;
// for (int i=0;i<n;i++)
// if (b[1+y]*i%n!=b[i+y]) fl=1;
// if (!fl) res=min(res,b[1+y]+2);
if (b[1+y]*sum%Mod==((cc[n-1+y]-cc[0+y-1]*ba2[n])%Mod+Mod)%Mod)
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: 0
Wrong Answer
time: 1ms
memory: 7820kb
input:
5 1 3 0 2 4
output:
2
result:
wrong answer 1st numbers differ - expected: '3', found: '2'