QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#616292 | #6748. Spin the Wheel | mojo__hugo# | WA | 6ms | 3956kb | C++20 | 1.8kb | 2024-10-06 01:10:42 | 2024-10-06 01:10:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define ull unsigned long long
using PII = pair<int, int>;
using ld = long double;
const int N = 1e5 + 5, M = 998244353;
typedef __int128 lll;
istream &operator>>(istream &cin, lll &x) { x=0; static string s; cin>>s; for (char c:s) x=x*10+(c-'0'); return cin; }
ostream &operator<<(ostream &cout, lll x) { static char s[60]; int tp=1; s[0]='0'+(x%10); while (x/=10) s[tp++]='0'+(x%10); while (tp--) cout<<s[tp]; return cout; }
mt19937_64 rng{ chrono::steady_clock::now().time_since_epoch().count() };
template <typename T>
int Min_show(T& A) {
int i = 0, j = 1, k = 0;
int n = A.size();
while (i < n && j < n && k < n) {
if (A[(i + k) % n] == A[(j + k) % n])k++;
else {
if (A[(i + k) % n] > A[(j + k) % n]) i += k + 1;
else j += k + 1;
if (i == j)i++;
k = 0;
}
}
return min(i, j);
}
void solve() {
int n;
cin >> n;
vector<int>a(n);
for (int i = 0;i < n;i++) {
cin >> a[i];
}
ll d = (a[1] - a[0] + n) % n;
for (int i = 2;i < n;i++) {
if (d != (a[i] - a[i - 1] + n) % n) {
cout << -1;
return;
}
}
vector<int>b(n);
for (int i = 0;i < n;i++) {
b[i] = i * d % n;
}
if (a == b) {
cout << d;
return;
}
int x = Min_show(a), y = Min_show(b);
for (int i = 0;i < n;i++) {
if (a[(i + x) % n] != b[(i + y) % n]) {
cout << -1;
return;
}
}
cout << d + (a[0] != 0);
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
int tt = 1;
// cout << fixed << setprecision(5);
// cin >> tt;
while (tt--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
5 1 3 0 2 4
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 5ms
memory: 3956kb
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: 5ms
memory: 3888kb
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: 6ms
memory: 3876kb
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'