# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
109495 | updown1 | 고대 책들 (IOI17_books) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N)
#define ffj For(j, 0, M)
#define ffa ffi ffj
//#define s <<" "<<
#define w cout
#define e "\n"
#define pb push_back
#define mp make_pair
#define a first
#define b second
#define int ll
const int MAXN = 1000000;
//Global Variables
int N, out = 0, loc[MAXN];
bool vis[MAXN];
void go(int at) {
if (vis[at]) return;
vis[at] = true;
out += abs(loc[at]-at);
go(loc[at]);
}
int minimum_walk(vector<int> p, int s) {
N = p.size();
ffi loc[i] = p[i];
int far_rig = 0, far_lef = 0;
For (i, s, N) if (!vis[i]) {far_rig = i; go(i);}
for (int i=s-1; i>=0; i--) if (!vis[i]) {far_lef = i; go(i);}
return out+2*((s-far_lef)+(far_rig-s));
}