# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
355219 | nicolaalexandra | Crazy old lady (IZhO13_crazy) | C++14 | 20 ms | 512 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.
#include <bits/stdc++.h>
#define DIM 1010
using namespace std;
int v[DIM],f[DIM];
int t,n,i;
int check (int poz){
memset (f,0,sizeof f);
f[v[1]] = 1;
for (int i=2;i<=n;i++){
if (i <= poz){
if (!f[i-1] && v[i] != i-1)
return 0;
if (f[v[i]])
return 0;
f[v[i]] = 1;
} else {
if (!f[i] && v[i] != i)
return 0;
if (f[v[i]])
return 0;
f[v[i]] = 1;
}
}
return 1;
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>t;
for (;t--;){
cin>>n;
for (i=1;i<=n;i++)
cin>>v[i];
int sol = 0, cnt = 0;
for (i=1;i<=n;i++){
if (check(i)){
sol = i;
cnt++;
}
}
if (cnt == 1)
cout<<sol<<"\n";
else cout<<"0\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |