# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47533 | cheater2k | Crazy old lady (IZhO13_crazy) | C++17 | 35 ms | 660 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>
using namespace std;
const int N = 1005;
int n;
bool taken[N];
int a[N];
int who[N];
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
int cnt = 0;
int seat = 0;
for (int crazy = 1; crazy <= n; ++crazy) {
who[1] = crazy;
for (int i = 2, cur = 1; i <= n; ++i, ++cur) {
if (cur == crazy) ++cur;
who[i] = cur;
}
for (int i = 1; i <= n; ++i) taken[i] = false;
taken[a[1]] = true;
bool ok = true;
for (int i = 2; i <= n; ++i) {
if (taken[who[i]]) {
if (taken[a[i]]) ok = false;
taken[a[i]] = true;
} else {
if (a[i] != who[i]) ok = false;
taken[who[i]] = true;
}
}
if (ok) {
++cnt;
seat = crazy;
}
}
printf("%d\n", (cnt == 1) ? seat : 0);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while(tt--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |