# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
766965 | danikoynov | Ancient Books (IOI17_books) | C++14 | 1 ms | 316 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;
typedef long long ll;
const int maxn = 1e6 + 10;
int used[maxn], n;
long long minimum_walk(vector<int> p, int s) {
n = p.size();
int cnt = 0;
ll mx = 0, ans = 0;
int to = 0;
for (int i = 0; i < n; i ++)
{
if (p[i] == i)
continue;
ans = ans + (ll)abs(i - p[i]);
///cout << ans << endl;
if (!used[i])
{
int local_max = i;
int v = p[i];
while(v != i)
{
local_max = max(local_max, v);
used[v] = 1;
v = p[v];
}
if (to < local_max)
mx = i;
to = max(to, local_max);
used[v] = 1;
}
}
return ans + 2 * mx;
}
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... |