# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
340174 | beksultan04 | Crazy old lady (IZhO13_crazy) | C++14 | 50 ms | 400 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 pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define ll long long
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
const int N = 2e5+12,INF=1e9+7;
int q[N],p[N],n,a[N];
bool is(int x){
p[q[1]]=1;
int c=1,i,f=1;
for (i=2;i<=n;++i){
if (c == x)c++;
a[i] = c;c++;
}
for (i=2;i<=n;++i){
if (p[a[i]] == 0 && q[i] != a[i])f = 0;
p[q[i]]=1;
}
for (i=1;i<=n;++i)p[i]=0;
ret f;
}
main(){
int t;
scan1(t)
while (t--){
int i,j,s=0,cnt=0;
scan1(n)
for (i=1;i<=n;++i)
scan1(q[i])
for (i=1;i<=n;++i){
if (is(i)){
s=i;
cnt++;
}
}
if (cnt > 1)s=0;
cout <<s<<"\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |