# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136734 | StevenH | Ancient Books (IOI17_books) | C++14 | 3 ms | 376 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 <cstdio>
using namespace std;
const int maxn=1000005;
bool vis[maxn];
bool loop[maxn];
long long aabs(int x)
{
long long xx = (long long)(x);
if(x<0)return -1*x;
else return x;
}
long long minimum_walk(std::vector<int> p, int s) {
long long ans=0;
for(int i=0;i<p.size();i++)
{
if(vis[i]==0)
{
int k=i;
do
{
vis[k]=1;
//break;
//printf("%d %d\n",k,p[k]);
ans+=aabs(p[k]-k);
k=p[k];
}while(k!=i);
}
}
for(int i=0;i<p.size();i++)
{
if(i==p[i])
loop[i]=1;
else loop[i]=0;
}
int k=0;
while(loop[k]==1)k++;
if(k==p.size())return 0;
ans+=k*2;
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... |