#include "books.h"
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
int n;
ll minimum_walk(vector < int > p, int s) {
n=p.size();
ll br=0;
int pos=0;
int tren=-1;
int l=0, d=n;
bool pp=0;
for(int i=0; i<n; i++){
if(p[i]!=i){
l=i;
pp=1;
break;
}
}
if(!pp){
return 0;
}
for(int i=n-1; i>-1; i--){
if(p[i]!=i){
d=i+1;
break;
}
}
while(l<d){
br+=l-pos;
pos=l;
br+=(d-l-1)*2;
for(int i=l; i<d; i++){
if(p[i]!=i){
if(tren<p[i]){
swap(p[i], tren);
}
}
else if(tren==i){
swap(p[i], tren);
}
}
for(int i=d-1; i>=l; i--){
if(p[i]!=i){
if(tren>p[i]){
swap(p[i], tren);
}
}
else if(tren==i){
swap(p[i], tren);
}
}
pp=0;
for(int i=l; i<d; i++){
if(p[i]!=i){
l=i;
pp=1;
break;
}
}
if(!pp){
break;
}
for(int i=d-1; i>=l; i--){
if(p[i]!=i){
d=i+1;
break;
}
}
for(int i=0; i<n; i++){
cout << p[i] << ' ';
}
cout << endl;
}
br+=pos;
return br;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Incorrect |
1 ms |
216 KB |
secret mismatch |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Incorrect |
1 ms |
216 KB |
secret mismatch |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Incorrect |
1 ms |
216 KB |
secret mismatch |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
secret mismatch |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Incorrect |
1 ms |
216 KB |
secret mismatch |
4 |
Halted |
0 ms |
0 KB |
- |