# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
428063 | inwbear | Ancient Books (IOI17_books) | C++14 | 157 ms | 8132 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;
set<pair<int,int> >ss;
long long ans=0;
long long minimum_walk(std::vector<int> p, int s)
{
int ed=0,rr=0,sw1=s,sw2=s;
for(int i=0;i<p.size();i++)
{
if(p[i]!=i)
{
sw1=min(sw1,min(i,p[i]));
sw2=max(sw2,max(i,p[i]));
}
}
for(int i=0;i<p.size();i++)
{
ed=max(ed,p[i]);
if(sw1==i)rr=0;
if(sw2==i)ans+=rr*2;
if(ed==i)
{
rr++;
}
ans+=abs(i-p[i]);
}
return ans;
}
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... |