#include "books.h"
#include <bits/stdc++.h>
using namespace std;
int p,d,h;
vector<int>P;
void movel(int x){
for(int i=p;i>=x;i--){
if(h>P[i]){
swap(h,P[i]);
}
}
d+=p-x;
p=x;
}
void mover(int x){
for(int i=p;i<=x;i++){
if(h<P[i]){
swap(h,P[i]);
}
}
d+=x-p;
p=x;
}
long long minimum_walk(vector<int>ppp,int S){
P=ppp;
assert(S==0);
int N=P.size();
p=0;
d=0;
h=P[0];
P[0]=-1;
for(int i=N-1;i>0;i--){
if(P[i]==i)continue;
for(int j=0;j<N;j++){
if(P[j]==i){
if(j<p)movel(j);
if(i<p)movel(i);
mover(i);
break;
}
}
}
return d+p;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Incorrect |
0 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '8', found: '4' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Incorrect |
0 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '8', found: '4' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Incorrect |
0 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '8', found: '4' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Incorrect |
0 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '8', found: '4' |
4 |
Halted |
0 ms |
0 KB |
- |