| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 293031 | Haunted_Cpp | 고대 책들 (IOI17_books) | C++17 | 1 ms | 512 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 5;
vector<int> p;
int last_p = -1;
long long solve(int idx, int carry) {
int current_location = idx;
int nxt_location = carry;
if (current_location != nxt_location) {
return abs(idx - nxt_location) + solve(nxt_location, carry);
}
assert(idx != -1);
int was = p[current_location];
p[current_location] = carry;
assert(was != carry);
carry = was;
nxt_location = carry;
if (carry == -1) {
last_p = idx;
return 0;
}
return abs(idx - nxt_location) + solve(nxt_location, carry);
}
long long minimum_walk(vector<int> p, int s) {
assert(s == 0);
::p = p;
const int n = p.size();
long long res = 0;
int idx = 0;
for (int i = 0; i < n; i++) {
if (p[i] != i) {
int was = ::p[i];
::p[i] = -1;
last_p = -1;
res += abs(idx - i) + solve(i, was);
if (is_sorted(::p.begin(), ::p.end())) {
return last_p + res;
}
idx = last_p;
}
}
}
컴파일 시 표준 에러 (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... | ||||
