# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
542829 | zggf | Ancient Books (IOI17_books) | C++14 | 191 ms | 28800 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> parent, ranga;
int find(int x){
if(parent[x]==-1) return x;
parent[x] = find(parent[x]);
return parent[x];
}
void join(int a, int b){
a = find(a);
b = find(b);
if(a==b) return;
if(ranga[a]>ranga[b]){
parent[b] = a;
}else if(ranga[b]>ranga[a]){
parent[a] = b;
}else{
parent[b] = a;
ranga[a]++;
}
}
long long minimum_walk(std::vector<int> p, int s) {
int n = p.size();
vector<int> odw(n);
parent.resize(n, -1);
ranga.resize(n);
long long wyn = 0;
vector<pair<int, int>> inp;
for(int i = 0; i < n; i++){
int pt = i;
if(!odw[pt]){
if(p[pt]!=pt){
int mini = 1e9;
int maxi = -1e9;
while(!odw[pt]){
mini = min(mini, pt);
maxi = max(maxi, pt);
odw[pt] = true;
wyn+=abs(p[pt]-pt);
pt = p[pt];
}
inp.push_back({mini, maxi});
}else{
odw[pt] = true;
}
}
}
inp.push_back({s, s});
sort(inp.begin(), inp.end());
int dal = 0;
for(int i = 0; i < inp.size()-1; i++){
dal = max(dal, inp[i].second);
while(inp[i+1].first<dal){
i++;
dal = max(dal, inp[i].second);
if(i==inp.size()-1) break;
}
if(i<inp.size()-1){
wyn+=2*(inp[i+1].first-dal);
}
}
return wyn;
}
컴파일 시 표준 에러 (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... |