# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
118569 | tinjyu | Ancient Books (IOI17_books) | C++14 | 3 ms | 384 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;
bool tag[1000005];
int a[1000005];
long long int ans;
long long minimum_walk(std::vector<int> p, int s) {
int n=p.size();
int t=0;
int far=0;
for(int i=0;i<n;i++)
{
if(tag[i]==0)
{
if(i!=p[i])far=i;
int t=i,f=i;
while(tag[p[t]]==0)
{
f=max(p[t],f);
ans+=abs(t-p[t]);
tag[p[t]]=1;
t=p[t];
}
for(int j=i+1;j<=f;j++)
{
if(tag[j]==0)
{
t=j;
while(tag[p[t]]==0)
{
ans+=abs(t-p[t]);
tag[p[t]]=1;
t=p[t];
}
}
}
i=f;
}
}
ans+=far+far;
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... |