# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105224 | bert30702 | Ancient Books (IOI17_books) | C++17 | 3 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 <bits/stdc++.h>
#include "books.h"
using namespace std;
const int MX = 1e6 + 100;
int G[MX];
long long minimum_walk(vector<int> p, int s) {
while(p.back() == p.size() - 1 and p.back() != s) p.pop_back();
int n = p.size();
long long sum = 0;
for(int i = 0; i < n; i ++) {
G[p[i]] = max(G[p[i]], i);
G[i] = max(G[i], p[i]);
sum += abs(i - p[i]);
}
for(int i = 0; i + 1 < n; i ++) {
if(p[i] == i and i != s) continue;
int ptr = i + 1;
while(ptr <= G[i]) {
G[i] = max(G[i], G[ptr]);
ptr ++;
}
if(ptr < n) sum += 2;
i = ptr - 1;
}
return sum;
}
//main () {
// cout << minimum_walk({2, 3, 0, 1}, 0);
//}
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... |