# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
204151 | Kalam | Crazy old lady (IZhO13_crazy) | C++11 | 13 ms | 380 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// KALAM
# include<bits/stdc++.h>
using namespace std;
const int N = 1000 + 77;
int n , a[N];
bool M[N];
inline bool Check(int x) {
memset(M , 0 , sizeof M);
int cur = 1;
M[a[cur ++]] = 1;
for(int i = 1;i <= n;++ i) {
if(i == x)
continue ;
if(! M[i]) {
if(a[cur ++] != i)
return 0;
M[i] = 1;
} else {
if(M[a[cur]])
return 0;
M[a[cur ++]] = 1;
}
}
return 1;
}
inline void Test() {
scanf("%d" , & n);
for(int i = 1;i <= n;++ i)
scanf("%d" , a + i);
vector < int > A;
for(int i = 1;i <= n;++ i)
if(Check(i))
A.push_back(i);
int sz = A.size();
printf("%d\n" , (sz == 1 ? A[0] : 0));
}
int main() {
int T;
scanf("%d" ,& T);
while(T --)
Test();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |