Submission #5418

# Submission time Handle Problem Language Result Execution time Memory
5418 2014-04-30T14:43:37 Z Qwaz Crazy old lady (IZhO13_crazy) C++
100 / 100
12 ms 1092 KB
#include <cstdio>

const int MAX = 1020;

int n, data[MAX];

void input(){
	scanf("%d", &n);

	int i;
	for(i = 0; i<n; i++)
		scanf("%d", &data[i]);
}

bool empty[MAX];

void solve(){
	int ans = -1;

	int i, j;
	for(i = 1; i<=n; i++){
		for(j = 1; j<=n; j++)
			empty[j] = 1;
		empty[data[0]] = 0;

		int num = 1;
		for(j = 1; j<=n; j++){
			if(i == j) continue;

			if(empty[j] && j != data[num]){
				break;
			}
			empty[data[num]] = 0;
			num++;
		}

		if(j > n){
			if(ans == -1) ans = i;
			else {
				puts("0");
				return;
			}
		}
	}

	printf("%d\n", ans == -1 ? 0 : ans);
}

int main(){
	int numCase;
	for(scanf("%d", &numCase); numCase--;){
		input();

		solve();
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1092 KB Output is correct
2 Correct 0 ms 1092 KB Output is correct
3 Correct 0 ms 1092 KB Output is correct
4 Correct 0 ms 1092 KB Output is correct
5 Correct 0 ms 1092 KB Output is correct
6 Correct 0 ms 1092 KB Output is correct
7 Correct 0 ms 1092 KB Output is correct
8 Correct 0 ms 1092 KB Output is correct
9 Correct 0 ms 1092 KB Output is correct
10 Correct 0 ms 1092 KB Output is correct
11 Correct 0 ms 1092 KB Output is correct
12 Correct 0 ms 1092 KB Output is correct
13 Correct 0 ms 1092 KB Output is correct
14 Correct 4 ms 1092 KB Output is correct
15 Correct 4 ms 1092 KB Output is correct
16 Correct 0 ms 1092 KB Output is correct
17 Correct 8 ms 1092 KB Output is correct
18 Correct 8 ms 1092 KB Output is correct
19 Correct 4 ms 1092 KB Output is correct
20 Correct 12 ms 1092 KB Output is correct