Submission #47560

#TimeUsernameProblemLanguageResultExecution timeMemory
47560JohnTitorCrazy old lady (IZhO13_crazy)C++11
100 / 100
11 ms628 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, j, k) for(int i=(j); i<=(k); i++) #define FFOR(i, j, k) for(int i=(j); i<(k); i++) #define DFOR(i, j, k) for(int i=(j); i>=(k); i--) #define bug(x) cerr<<#x<<" = "<<(x)<<'\n' #define pb push_back #define mp make_pair #define setbit(s, i) (s|=(1LL<<(i))) #define bit(s, i) (((s)>>(i))&1LL) #define mask(i) ((1LL<<(i))) #define builtin_popcount __builtin_popcountll typedef long long ll; typedef long double ld; template <typename T> inline void read(T &x){ char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){ nega=1; c=getchar(); } x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x; } template <typename T> inline void writep(T x){ if(x>9) writep(x/10); putchar(x%10+48); } template <typename T> inline void write(T x){ if(x<0){ putchar('-'); x=-x; } writep(x); } template <typename T> inline void writeln(T x){ write(x); putchar('\n'); } #define taskname "E" int n; int p[1001]; bool used[1001]; bool check(int u){ FOR(i, 1, n) used[i]=0; used[p[1]]=1; int j=1; FFOR(i, 1, u){ j++; if((!used[i])&&(p[j]!=i)) return 0; used[p[j]]=1; } FOR(i, u+1, n){ j++; if((!used[i])&&(p[j]!=i)) return 0; used[p[j]]=1; } return 1; } void solve(){ read(n); FOR(i, 1, n) read(p[i]); vector <int> ans; FOR(j, 1, n) if(check(j)){ ans.pb(j); if(ans.size()>1){ puts("0"); return; } } writeln(ans[0]); } int main(){ #ifdef Kanikou if(fopen(taskname".inp", "r")) freopen(taskname".inp", "r", stdin); #endif // Kanikou int t; read(t); while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...