#include "books.h"
#define dbg(x) cerr<<#x<<": "<<x<<endl
#define here cerr<<"================================\n"
#include <bits/stdc++.h>
#define ll long long
#define llinf 1000000000000000000LL
#define pb push_back
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define fi first
#define sc second
#define endl '\n'
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 1000005
ll n,st,it;
ll a[maxn],col[maxn];
vector<ll> g[maxn];
long long minimum_walk(vector<int> p, int s) {
n = sz(p);
for(ll i = 1;i<=n;i++) a[i] = p[i-1]+1;
st = s;
ll ans = 0;
for(ll i = 1;i<=n;i++){
if(col[i]) continue;
if(i==a[i]) continue;
ll x = a[i];
ans+=abs(i-a[i]);
it++;
col[i] = it;
while(x!=i){
col[x] = it;
ans+=abs(x-a[x]);
x = a[x];
}
}
set<ll> cur;
for(ll i = 1;i<=n;i++){
if(col[i]) cur.insert(col[i]);
if(sz(cur)==it){
ans+=2*(i-1);
break;
}
}
return ans;
}
/*
4 0
0 2 3 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23792 KB |
Output is correct |
2 |
Correct |
14 ms |
23792 KB |
Output is correct |
3 |
Correct |
12 ms |
23752 KB |
Output is correct |
4 |
Correct |
12 ms |
23788 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Incorrect |
12 ms |
23704 KB |
3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23792 KB |
Output is correct |
2 |
Correct |
14 ms |
23792 KB |
Output is correct |
3 |
Correct |
12 ms |
23752 KB |
Output is correct |
4 |
Correct |
12 ms |
23788 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Incorrect |
12 ms |
23704 KB |
3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23792 KB |
Output is correct |
2 |
Correct |
14 ms |
23792 KB |
Output is correct |
3 |
Correct |
12 ms |
23752 KB |
Output is correct |
4 |
Correct |
12 ms |
23788 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Incorrect |
12 ms |
23704 KB |
3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
23752 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '4728' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23792 KB |
Output is correct |
2 |
Correct |
14 ms |
23792 KB |
Output is correct |
3 |
Correct |
12 ms |
23752 KB |
Output is correct |
4 |
Correct |
12 ms |
23788 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Incorrect |
12 ms |
23704 KB |
3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 |
Halted |
0 ms |
0 KB |
- |