# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47561 | nickyrio | Crazy old lady (IZhO13_crazy) | C++17 | 12 ms | 748 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define DEBUG(x) { cerr << #x << '=' << x << endl; }
#define Arr(a, l, r) { cerr << #a << " = {"; FOR(_, l, r) cerr << ' ' << a[_]; cerr << "}\n"; }
#define N 1001000
#define pp pair<int, int>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define taskname ""
#define bit(S, i) (((S) >> (i)) & 1)
using namespace std;
int n, p[N], pos[N], mark[N];
bool Ok(int crazy) {
FOR(i, 1, n) mark[i] = 0;
mark[p[1]] = 1;
int now = 1;
FOR(i, 1, n) if (i != crazy) {
now++;
if (mark[i] == 0) {
if (p[now] != i) return false;
} else {
if (mark[p[now]]) return false;
}
mark[p[now]] = 1;
}
return true;
}
void Solve() {
cin >> n;
FOR(i, 1, n) cin >> p[i];
int cnt = 0, z;
FOR(i, 1, n) if (Ok(i)) {
cnt++; z = i;
}
if (cnt == 1) cout << z << '\n';
else cout << 0 << '\n';
}
int main() {
#ifdef NERO
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
double stime = clock();
#else
//freopen(taskname".inp","r",stdin);
//freopen(taskname".out","w",stdout);
#endif //NERO
IO;
int test;
cin >> test;
while (test--) Solve();
#ifdef NERO
double etime = clock();
cerr << "Execution time: " << (etime - stime) / CLOCKS_PER_SEC * 1000 << " ms.\n";
#endif // NERO
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |