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"
#pragma GCC optimize("Ofast")
#define x first
#define y second
#define ld long double
#define ll long long
using namespace std;
int n, s, x;
ll minimum_walk(vector <int> p, int s) {
ll ans = 0;
int n = p.size(), r = -1;
vector <bool> viz(n + 5);
for(int i = 0; i < n; i++) {
if(!viz[i]) {
int j = i;
while(!viz[j]) {
ans += abs(j - p[j]);
viz[j] = 1;
j = p[j];
}
r = max(r, i);
}
}
return ans + 2 * r;
}
/*int main() {
ios_base :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> s;
vector <int> p;
for(int i = 1; i <= n; i++)
cin >> x, p.push_back(x);
cout << minimum_walk(p, s);
return 0;
}
*/
# | 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... |