# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47560 | JohnTitor | Crazy old lady (IZhO13_crazy) | C++11 | 11 ms | 628 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>
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |