Submission #882530

#TimeUsernameProblemLanguageResultExecution timeMemory
882530alexddCrazy old lady (IZhO13_crazy)C++17
100 / 100
5 ms500 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[1]]=1; int assigned=0; for(int i=2;i<=n;i++) { assigned++; if(assigned==lady) assigned++; 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=i; else { unde=0; break; } } } //cout<<" zzz\n"; cout<<unde<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...