# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
160360 | BlueDiamond | 곤돌라 (IOI14_gondola) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
const int L = 250000 + 7;
int who[L];
int valid(int n, int a[]) {
memset(who, -1, sizeof who);
for (int i = 0; i < n; i++) {
a[i]--;
who[a[i]] = i;
}
int i = L - 1;
while (i >= 0) {
if (who[i] == -1) {
i--;
continue;
}
int j = i - 1;
while (j >= 0 && who[j] != -1)
j--;
if (j < 0)
break;
who[j] = who[i];
who[i] = -1;
i = j - 1;
}
for (int i = 0; i < n; i++)
if (who[i] == -1)
return -1;
for (int i = 1; i < n; i++) {
int dist = who[i] - who[i - 1];
if (dist < 0)
dist += n;
if (dist != 1)
return 0;
}
return 1;
}