제출 #70240

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
702402018-08-22 14:02:19E869120Ancient Books (IOI17_books)C++14
50 / 100
303 ms107868 KiB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
int n,c[1000009];bool used[1000009];
long long minimum_walk(vector<int> p, int s) {
n=p.size();
long long sum=0;
for(int i=0;i<n;i++){
if(used[i]==true || i==p[i]) continue;
int cx=i, maxn=0;
while(true){
sum+=abs(cx-p[cx]);used[cx]=true;maxn=max(maxn,cx);
cx=p[cx];if(cx==i) break;
}
c[i]++;c[maxn]--;
}
for(int i=1;i<=n;i++) c[i]+=c[i-1];
long long L=0;bool flag=false;
for(int i=n;i>=0;i--){
if(c[i]==1) flag=true;
if(flag==true && c[i]==0) L++;
}
return sum+L*2;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...