# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
135205 | anayk | Ancient Books (IOI17_books) | C++14 | 162 ms | 14968 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 <iostream>
#include "books.h"
int min, max;
int l, r;
int n, low;
void add(int val)
{
min = std::min(min, val);
max = std::max(max, val);
}
long long minimum_walk(std::vector<int> p, int s)
{
n = p.size();
low = 0;
long long answer = 0;
for(int i = 0; i < p.size(); i++)
answer += (long long) abs(i-p[i]);
while(p[n-1] == n-1 && n-1 > s)
n--;
while(p[low] == low && low < s)
low++;
min = max = l = r = s;
add(p[s]);
while(min > low || max < n-1)
{
if(l > min)
{
l--;
add(p[l]);
}
else if(r < max)
{
r++;
add(p[r]);
}
else
{
answer += 2;
if(max < n-1)
max++;
else
min--;
}
}
return answer;
}
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... |