# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
47561 | nickyrio | 성질 급한 지학이 (IZhO13_crazy) | C++17 | 12 ms | 748 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define DEBUG(x) { cerr << #x << '=' << x << endl; }
#define Arr(a, l, r) { cerr << #a << " = {"; FOR(_, l, r) cerr << ' ' << a[_]; cerr << "}\n"; }
#define N 1001000
#define pp pair<int, int>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define taskname ""
#define bit(S, i) (((S) >> (i)) & 1)
using namespace std;
int n, p[N], pos[N], mark[N];
bool Ok(int crazy) {
FOR(i, 1, n) mark[i] = 0;
mark[p[1]] = 1;
int now = 1;
FOR(i, 1, n) if (i != crazy) {
now++;
if (mark[i] == 0) {
if (p[now] != i) return false;
} else {
if (mark[p[now]]) return false;
}
mark[p[now]] = 1;
}
return true;
}
void Solve() {
cin >> n;
FOR(i, 1, n) cin >> p[i];
int cnt = 0, z;
FOR(i, 1, n) if (Ok(i)) {
cnt++; z = i;
}
if (cnt == 1) cout << z << '\n';
else cout << 0 << '\n';
}
int main() {
#ifdef NERO
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
double stime = clock();
#else
//freopen(taskname".inp","r",stdin);
//freopen(taskname".out","w",stdout);
#endif //NERO
IO;
int test;
cin >> test;
while (test--) Solve();
#ifdef NERO
double etime = clock();
cerr << "Execution time: " << (etime - stime) / CLOCKS_PER_SEC * 1000 << " ms.\n";
#endif // NERO
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |