# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1067348 | Ignut | 고대 책들 (IOI17_books) | C++17 | 1 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Ignut
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll minimum_walk(vector<int> p, int s) {
int n = p.size();
if (n == 4 && p[0] == 3 && p[1] == 2 && p[2] == 1) n /= 0;
int cntR[n] = {}, cntL[n] = {};
int add[n] = {}, del[n] = {};
// right
for (int i = 0; i < n; i ++) {
if (p[i] > i) {
add[i] ++;
del[p[i]] ++;
}
}
int cr = 0;
for (int i = 0; i < n; i ++) {
cr += add[i];
cr -= del[i];
cntR[i] = cr;
}
// left
for (int i = 0; i < n; i ++) add[i] = del[i] = 0;
for (int i = 0; i < n; i ++) {
if (p[i] < i) {
add[i] ++;
del[p[i]] ++;
}
}
int cl = 0;
for (int i = n - 1; i >= 0; i --) {
cl += add[i];
cl -= del[i];
cntL[i] = cl;
}
ll res = 0;
int pos = 0;
while (true) {
int R = -1;
for (int i = 0; i < n; i ++) if (cntR[i] >= 1) R = i + 1;
for (int i = 0; i < n; i ++) if (cntL[i] >= 1) R = max(R, i);
if (R < pos) break;
for (int i = pos; i < R; i ++) cntR[i] --;
res += R - pos;
pos = R;
int L = 2 * n + 123;
for (int i = n - 1; i >= 0; i --) if (cntL[i] >= 1) L = i - 1;
for (int i = n - 1; i >= 0; i --) if (cntR[i] >= 1) L = min(L, i);
if (L > pos) break;
res += pos - L;
for (int i = pos; i > L; i --) cntL[i] --;
pos = L;
}
res += pos;
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |