# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
770138 | APROHACK | 고대 책들 (IOI17_books) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
int n;
int startTo[1000000];
int searchR(int pos){
for(int i = pos ; i < n ; i ++){
if(startTo[i] != -1)return i;
}
return -1;
}
ll searchL(ll pos){
for(int i = 0 ; i < n; i ++){
if(startTo[i] != -1)return i;
}
return -1;
}
ll pos = 0, temp;
ll ans = 0;
void ir(ll siguiente){
ans += abs(siguiente-pos);
pos = siguiente;
}
long long minimum_walk(std::vector<> p, int s) {
n = p.size();int
for(int i = 0 ; i < n ; i ++){
startTo[i] = -1;
if(p[i] > i){
startTo[i] = p[i];
}
}
while(true){
ll nextL = searchL(pos);
if(nextL != -1){
ir(nextL);
temp = pos;
ir(startTo[pos]);
startTo[temp] = -1;
continue;
}
ans+= pos;
return ans;
}
}