# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
71215 | Kmcode | Ancient Books (IOI17_books) | C++14 | 256 ms | 16336 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
//#include "books.h"
using namespace std;
int im1[1000002];
int im2[1000002];
long long minimum_walk(std::vector<int> p, int s) {
for(int i=0;i<p.size();i++){
if(i<=p[i]){
im1[i]++;
im1[p[i]]--;
}
else{
im2[p[i]]++;
im2[i]--;
}
}
for(int i=1;i<p.size();i++){
im1[i]+=im1[i-1];
im2[i]+=im2[i-1];
}
int ava=0;
long long int turn=0;
for(int i=p.size()-1;i>=s;i--){
if(im1[i]||im2[i]){
ava=1;
}
int need=max(im1[i],im2[i]);
need*=2;
need=max(need,ava*2);
turn+=need;
}
ava=0;
for(int i=0;i<s;i++){
if(im1[i]||im2[i]){
ava=1;
}
int need=max(im1[i],im2[i]);
need*=2;
need=max(need,ava*2);
turn+=need;
}
return turn;
}
Compilation message (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... |