#include"books.h"
#include <vector>
#include<bits/stdc++.h>
const int maxn=1000000+10;
using namespace std;
int vis[maxn],visa[maxn];
int n;
long long minimum_walk(std::vector<int> p, int s){
n=p.size();
long long mainres=0,last=0;
int cnt1=0;
for(int i=0;i<n;i++){
if(p[i]>i){
cnt1++;
visa[p[i]]=1;
}
if(visa[i]){
cnt1--;
}
mainres+=cnt1*2;
if(cnt1!=0){
last=i+1;
}
}
for(int i=0;i<=last;i++){
if(vis[i]==0){
mainres+=2;
int now=i;
do{
vis[now]=1;
now=p[now];
}while(now!=i);
}
}
mainres-=2;
return mainres;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '4186' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |