이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll , ll> ii;
#define ff first
#define ss second
#define pb push_back
#define in insert
long long minimum_walk(std::vector<int> p, int s) {
ll n = p.size();
vector < ll > vis(n, 0);
ll ans = 0; ll r = 0;
ll mx = 0;
while(n > 0 && p[n-1] == n-1){
n--;
}
if(n == 0) return 0;
for(ll i = 0; i < n; i++){
if(vis[i]) continue;
ll c = i;
ll _mx = 0;
while(!vis[c]){
vis[c] = 1;
_mx = max(_mx, c);
ans += abs(p[c] - c); c = p[c];
}
if(mx < i) r++;
mx = max(mx, _mx);
}
ans += 2*r;
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |