#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn = 1007;
ll t, n, cnt, sol;
ll seats[maxn];
ll visited[maxn];
void solve(){
cnt = 0, sol = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> seats[i], seats[i]--;
}
for (int k = 0; k < n; k++) {
bool pos = true;
for (int i = 0; i < n; i++) visited[i] = 0;
visited[seats[0]] = 1;
int j = 0;
for (int i = 0; i < n; i++) {
if (i == k) continue;
j++;
if (visited[i] == 0 && seats[j] != i) {
pos = false;
break;
}
visited[seats[j]] = 1;
}
if (pos) {
cnt++;
sol = k;
}
}
if (cnt > 1) cout << "0\n";
else cout << sol+1 << '\n';
}
int main(){
cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
4 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
448 KB |
Output is correct |
19 |
Correct |
4 ms |
348 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |