Submission #882528

#TimeUsernameProblemLanguageResultExecution timeMemory
882528alexddCrazy old lady (IZhO13_crazy)C++17
0 / 100
1 ms348 KiB
#include<iostream> using namespace std; int n; int p[1005]; bool occupied[1005]; bool verif(int lady) { for(int i=1;i<=n;i++) occupied[i]=0; occupied[p[lady]]=1; int assigned=0; for(int i=1;i<=n;i++) { assigned++; if(i==lady) { assigned--; continue; } if(!occupied[assigned]) { if(p[i]!=assigned) return 0; occupied[p[i]]=1; } else { if(p[i]==assigned) return 0; occupied[p[i]]=1; } } return 1; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0); int t; cin>>t; while(t--) { cin>>n; for(int i=1;i<=n;i++) { cin>>p[i]; } int unde=-1; for(int i=1;i<=n;i++) { if(verif(i)) { // cout<<i<<" "; // continue; if(unde==-1) unde=p[i]; else { unde=0; break; } } } // cout<<" zzz\n"; cout<<unde<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...