| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 585791 | InternetPerson10 | 고대 책들 (IOI17_books) | C++17 | 327 ms | 37812 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<ll> rands;
vector<int> dist;
map<ll, int> ma;
long long minimum_walk(vector<int> p, int s) {
srand(time(NULL));
int n = p.size();
rands.resize(n, 0);
for(int i = 0; i < n; i++) {
for(int j = 0; j < 4; j++) {
rands[i] *= 32768;
rands[i] += (rand() % 32768);
}
}
ll tot = 0;
vector<bool> taken(n, false);
vector<int> nums(n, -1);
for(int i = 0; i < n; i++) {
if(!taken[i]) {
int x = i;
int l = i, r = i;
while(!taken[x]) {
taken[x] = true;
tot += abs(x - p[x]);
x = p[x];
l = min(l, x);
r = max(r, x);
}
if(l != r) {
nums[l] = nums[r] = l;
}
}
}
ll hash = 0;
int lastZero = 0;
int lastImpt = -999999;
bool foundC = false;
int l1 = s-1, r1 = s;
for(int i = 0; i < n; i++) {
if(nums[i] == -1) {
if(hash == 0) tot += 2;
continue;
}
lastImpt = i;
hash ^= rands[nums[i]];
if(hash) {
if(ma.count(hash)) {
int l = ma[hash], r = i;
if(l <= l1 && r1 <= r) {
tot += 2 * min(r - r1, l1 - l);
}
ma.erase(hash);
}
else ma[hash] = i;
}
else {
if(i != lastZero) tot += 2;
lastZero = i + 1;
}
}
for(int i = 0; i < n; i++) {
if(p[i] == i && i != s) tot -= 2;
else break;
}
for(int i = n-1; i >= 0; i--) {
if(p[i] == i && i != s) tot -= 2;
else break;
}
return max(0LL, tot - 2);
}
컴파일 시 표준 에러 (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... | ||||
