# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
790188 | Sohsoh84 | 곤돌라 (IOI14_gondola) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define sep ' '
#define debug(x) cerr << #x << ": " << x << endl;
const int MAXN = 1e6 + 10;
int A[MAXN];
int valid(int n, int inputSeq[]) {
int s = -1;
set<int> tst;
for (int i = 0; i < n; i++) inputSeq[i]--;
for (int i = 0; i < n; i++) {
if (inputSeq[i] < n)
s = i;
tst.insert(inputSeq[i]);
}
if (int(tst.size()) < n) return 0;
if (s == -1) return 1;
int shift_val = (s - inputSeq[s] + n) % n;
for (int j = 0; j < n; j++)
A[j] = inputSeq[(j + shift_val) % n];
set<int> st;
for (int i = 0; i < n; i++) {
if (A[i] < n)
if (A[i] != i) return 0;
else
A[i] = i;
st.insert(A[i]);
}
return st.size() == n;
}
//----------------------
int replacement(int n, int gondolaSeq[], int res[]) {
for (int i = 0; i < n; i++) inputSeq[i]--;
for (int i = 0; i < n; i++) {
if (inputSeq[i] < n)
s = i;
}
int shift_val = (s == -1 ? 0 : (s - inputSeq[s] + n) % n);
for (int j = 0; j < n; j++)
A[j] = inputSeq[(j + shift_val) % n];
set<int> st;
int mx = *max_element(A, A + n);
for (int i = 0; i <= mx; i++)
st.insert(i);
for (int i = 0; i < n; i++)
st.erase(A[i]);
set<pll> gond;
for (int i = 0; i < n; i++)
gond.insert({A[i], i});
int m = 0;
while (gond.rbegin() -> X > n) {
auto [x, ind] = *prev(gond.end());
gond.erase(prev(gond.end()));
if (st.find(x - 1) != st.end()) {
A[ind] = x - 1;
st.erase(x - 1);
res[m++] = x - 1;
} else {
A[ind] = ind;
st.erase(ind);
res[m++] = ind;
}
gond.insert(A[ind, ind]);
}
reverse(res, res + m);
return m;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
return -3;
}