#include "bits/stdc++.h"
using namespace std;
vector<int> P;
int vis[1001];
void dfs(int i){
vis[i] = 1;
if(!vis[P[i]])dfs(P[i]);
}
long long minimum_walk(vector<int> p, int s){
int ans = 0;
int n = p.size();
P.clear();
for(int i = 0;i<n;i++){
vis[i] = 0;
P.push_back(p[i]);
ans+=abs(i-p[i]);
}
vector<int> lol;
for(int i = 0;i<n;i++){
if(!vis[i]){
dfs(i);
lol.push_back(i);
}
}
int sz = lol.size();
ans+=(sz-1)*2;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 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 |
344 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 |
344 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 |
- |