# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
119137 | tinjyu | Ancient Books (IOI17_books) | C++14 | 163 ms | 16092 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;
long long int tag[1000005];
int l[1000005],r[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(i==p[i])continue;
ans+=abs(i-p[i]);
if(i>p[i])
{
tag[p[i]]++;
tag[i]--;
}
else
{
tag[i]++;
tag[p[i]]--;
}
}
for(int i=s+1;i<n;i++)tag[i]+=tag[i-1];
int r=s;
for(int i=n-1;i>=s;i--)
{
if(tag[i]!=0)
{
r=i+1;
break;
}
}
for(int i=s;i<r;i++)
{
if(tag[i]==0)ans+=2;
}
for(int i=s-1;i>=0;i--)tag[i]+=tag[i+1];
r=0;
for(int i=0;i<=s;i++)
{
if(tag[i]!=0)
{
r=i-1;
break;
}
}
for(int i=0;i<r;i++)
{
if(tag[i]==0)ans+=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... |