# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
119123 | tinjyu | Ancient Books (IOI17_books) | C++14 | 2 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;
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++)
{
ans+=abs(i-p[i]);
if(i>p[i])
{
tag[p[i]]++;
tag[i+1]--;
}
else
{
tag[i]++;
tag[p[i]+1]--;
}
}
int l=n-1;
for(int i=n-1;i>=0;i--)
{
if(tag[i]<0)break;
l=i-1;
}
int tmp=0;
for(int i=0;i<=l;i++)
{
tmp+=tag[i];
if(tmp==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... |