#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define FOR(i,a,b) for(int i=a; i<b; i++)
void dbgv(vi vec){for(int x: vec) cout << x << ' '; cout << endl; }
//---------------------------
int N;
vi a,p;
int check(){
FOR(i,0,N) if(a[i]==-1 || p[a[i]]!=i) return 0;
return 1;
}
ll minimum_walk(vi p, int s) {
::p=p;
N=sz(p);
a.resize(N);
iota(all(a),0);
int on=-1, i=s, ty=1;
ll ans=0;
while(!check()){
//dbgv(a);
if(a[i]!=-1 && p[a[i]]==i){
i+=ty;
ans++;
continue;
}
swap(a[i],on);
if(on!=-1){
if(i<p[on]) i++, ty=1;
else i--, ty=-1;
ans++;
}
}
ans+=i;
return ans;
}
/*
4 0
0 2 3 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
296 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '83501' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |