Submission #47533

# Submission time Handle Problem Language Result Execution time Memory
47533 2018-05-05T02:50:59 Z cheater2k Crazy old lady (IZhO13_crazy) C++17
100 / 100
35 ms 660 KB
#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
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 584 KB Output is correct
7 Correct 3 ms 584 KB Output is correct
8 Correct 5 ms 588 KB Output is correct
9 Correct 5 ms 600 KB Output is correct
10 Correct 6 ms 636 KB Output is correct
11 Correct 7 ms 636 KB Output is correct
12 Correct 9 ms 636 KB Output is correct
13 Correct 9 ms 636 KB Output is correct
14 Correct 11 ms 636 KB Output is correct
15 Correct 12 ms 636 KB Output is correct
16 Correct 16 ms 636 KB Output is correct
17 Correct 17 ms 652 KB Output is correct
18 Correct 28 ms 652 KB Output is correct
19 Correct 27 ms 660 KB Output is correct
20 Correct 35 ms 660 KB Output is correct