# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
411940 | losmi247 | Gondola (IOI14_gondola) | C++14 | 0 ms | 0 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;
typedef long long ll;
const int N = 1e5+34;
int n,a[N];
int pos[N];
int valid(int br,int *inputseq){
n = br;
for(int i = 1; i <= n; i++) a[i] = inputseq[i-1];
for(int i = 1; i <= n; i++){
if(a[i] <= n) pos[a[i]] = i;
}
int lst = 0;
bool ok = 1;
for(int i = 1; i <= n; i++){
if(!pos[i]) continue;
if(!lst){
lst = i;
continue;
}
if(pos[lst] < pos[i]){
if(pos[i]-pos[lst] != i-lst){
ok = 0;
break;
}
}
else{
if(pos[lst]-pos[i]-1 != lst-1+n-i){
ok = 0;
break;
}
}
lst = i;
}
return ok;
}
/*int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int a;
cin >> a;
int *niz = (int*)malloc(sizeof(int)*a);
for(int i = 0; i < a; i++) cin >> niz[i];
cout << valid(a,niz) << endl;
}*/