# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72801 | funcsr | 고대 책들 (IOI17_books) | C++17 | 289 ms | 47716 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 <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i,n)for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define _1 first
#define _2 second
#define INF 1145141919
typedef pair<int, int> P;
int N;
bool used[1000000];
int T[1000000];
vector<int> G[1000000];
long long minimum_walk(vector<int> A, int S) {
N = A.size();
int lmin = 0, rmin = 0;
rep(i, N) if (!used[i]) {
if (i == A[i]) continue;
int x = i;
while (!used[x]) {
if (x < A[x]) {
T[x]++;
T[A[x]]--;
}
used[x] = true;
x = A[x];
}
}
rep(i,N-1) T[i+1] += T[i];
assert(S==0);
long long cost = 0;
bool yes = false;
for (int i=N-1; i>=0; i--) {
if (T[i])yes=true;
cost += max(T[i], (int)yes);
}
return 2LL*cost;
}
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... |