Submission #355219

#TimeUsernameProblemLanguageResultExecution timeMemory
355219nicolaalexandraCrazy old lady (IZhO13_crazy)C++14
100 / 100
20 ms512 KiB
#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 timeMemoryGrader output
Fetching results...