#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=a; i<b; i++)
typedef vector<int>vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
typedef pair<ll,ll>pi;
typedef vector<pi>vpi;
#define fi first
#define se second
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const ll INF=1e18;
//-------------------------------------
int N;
vi p;
int dist(int i, int j){return abs(p[i]-p[j]);}
ll minimum_walk(vi p, int s) {
::p=p;
N=sz(p);
vi vis(N,0);
int x=0;
ll ans=0;
FOR(i,0,N) if(!vis[i]){
ans+=dist(i,x);
x=i;
int u=x;
while(1){
if(vis[u]) break;
vis[u]=1;
ans+=dist(u,p[u]);
u=p[u];
}
}
return ans;
}
/*
4 0
0 2 3 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '3830' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |