#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
lld n;
lld minimum_walk(vector<int> p, int s){
n = (lld) p.size();
lld ans = 0;
for(lld i=0;i<n;i++) ans+=abs(p[i]-i);
vector<bool> vis(n, false);
vector<vector<lld>> cycles;
vector<pair<lld,lld>> evs;
for(lld i=0;i<n;i++){
if(!vis[i]){
vector<lld> tmp;
lld x = i;
while(true){
if(vis[x]) break;
tmp.push_back(x);
vis[x] = true;
x = p[x];
}
cycles.push_back(tmp);
sort(tmp.begin(), tmp.end());
evs.push_back({tmp[0], 0});
evs.push_back({*tmp.rbegin(), 1});
}
}
sort(evs.begin(), evs.end());
lld op = 0;
vector<lld> newcycle;
for(lld i=0;i<(lld)evs.size();i++){
if(evs[i].second==0){
if(op==0) newcycle.push_back(evs[i].first);
op++;
}else{
op--;
}
}
return ans+2*((lld)newcycle.size()-1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 |
Halted |
0 ms |
0 KB |
- |