# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
135203 | anayk | Ancient Books (IOI17_books) | C++14 | 2 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 <iostream>
#include "books.h"
int min, max;
int l, r;
int n;
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();
long long answer = 0;
for(int i = 0; i < p.size(); i++)
answer += (long long) abs(i-p[i]);
min = max = l = r = s;
add(p[s]);
while(min > 0 || 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... |