# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
47533 | cheater2k | Crazy old lady (IZhO13_crazy) | C++17 | 35 ms | 660 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |