#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;
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;
}
}
cnt += ok;
}
//cerr << cnt << endl;
printf("%d\n", cnt == 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while(tt--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Incorrect |
2 ms |
408 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |