# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
423052 | MDario | Ancient Books (IOI17_books) | C++11 | 158 ms | 9156 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 "books.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
long long minimum_walk(vector<int> p, int s){
ll n=p.size(), r=0, x=0, y=0, z=0;
bool b[n];
for(int i=0; i<n; i++){
b[i]=0;
if(p[i]==i)b[i]=1;
}
for(int i=0; i<n; i++){
if(!b[i]){
//cout << z << " ";
if(i>z){
r+=2*(i-z);
}
r+=p[i]-i;
y=p[i];
while(y!=i){
z=max(z, y);
b[y]=1;
r+=abs(p[y]-y);
y=p[y];
}
b[y]=1;
z=max(z, y);
}
}
return r;
}
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... |