#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];
vector<int> G[1000000];
long long minimum_walk(vector<int> A, int S) {
N = A.size();
long long cost = 0;
int lmin = 0, rmin = 0;
rep(i, N) if (!used[i]) {
int x = i;
int left = -INF, right = INF;
while (!used[x]) {
if (x <= S) left = max(left, S-x);
else right = min(right, x-S);
used[x] = true;
cost += abs(A[x]-x);
x = A[x];
}
if (left == -INF) rmin = max(rmin, right);
else if (right == INF) lmin = max(lmin, left);
else {
G[left].pb(right);
}
//cout<<left<<"<->"<<right<<"\n";
}
assert(S==0);
int m = rmin;
/*
int m = INF;
for (int left=N-1; left>=lmin; left--) {
m = min(m, left+rmin);
for (int r : G[left]) rmin = max(rmin, r);
}
*/
return cost+2LL*m;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Incorrect |
25 ms |
23964 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Incorrect |
25 ms |
23964 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Incorrect |
25 ms |
23964 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
43 ms |
47576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23800 KB |
Output is correct |
2 |
Incorrect |
25 ms |
23964 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |