# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
129492 | antimirage | 곤돌라 (IOI14_gondola) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 5;
int b[N], ind[N], mx, sz, cnt[N], mod = 1e9 + 9;
int valid(int n, int a[]) {
int pos = -1;
for (int i = 0; i < n; i++) {
if (a[i] <= n) {
pos = i;
}
cnt[a[i]]++;
if (cnt[a[i]] > 1)
return 0;
}
if (pos == -1) {
return 1;
} else {
assert(a[pos] <= n);
int cn = a[pos];
for (int i = (pos + 1) % n; i != pos; i = (i + 1) % n) {
cn++;
if (cn > n)
cn -= n;
if (a[i] > n) {
continue;
}
if (a[i] != cn) {
return 0;
}
}
}
return 1;
}
int replacement(int n, int a[], int ans[]) {
memset(ind, -1, sizeof(ind));
int pos = -1;
for (int i = 0; i < n; i++) {
if (a[i] <= n) {
pos = i;
}
if (a[i] > a[mx]) {
mx = i;
}
ind[a[i]] = i;
}
if (pos == -1) {
for (int i = 0; i < n; i++) {
b[i] = i + 1;
}
}
else {
int cn = a[pos];
b[pos] = a[pos];
for (int i = (pos + 1) % n; i != pos; i = (i + 1) % n) {
cn++;
if (cn > n)
cn -= n;
b[i] = cn;
}
}
for (int i = n + 1; i <= a[mx]; i++) {
if (ind[i] == -1) {
ans[sz++] = b[mx];
b[mx] = i;
}
else {
ans[sz++] = b[ind[i]];
b[ind[i]] = i;
}
}
return sz;
}
long long binpow (long long a, int b) {
if (b == 0)
return 1;
if (b & 1)
return a * 1ll * binpow(a, b - 1) % mod;
long long asd = binpow(a, b >> 1);
return asd * 1ll * asd % mod;
}
int countReplacement(int n, int a[]) {
int pos = -1;
long long res = 1;
for (int i = 0; i < n; i++) {
if (a[i] <= n) {
pos = i;
}
}
if (pos == -1) {
res = n;
} else {
int cn = a[pos];
for (int i = (pos + 1) % n; i != pos; i = (i + 1) % n) {
cn++;
if (cn > n)
cn -= n;
if (a[i] > n) {
continue;
}
if (a[i] != cn) {
return 0;
}
}
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (a[i] <= n) continue;
if (i > 0 && a[i] == a[i - 1])
return 0;
res *= binpow((n - i) * 1ll, (i == 0 ? a[i] - n - 1 : a[i] - a[i - 1] - 1) );
res %= mod;
}
return res;
}