이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#define endl '\n'
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
const int N = 3e5+1;
const ll INF = 2e18;
const int MOD = 1e9+7;
long long minimum_walk(vector<int> p, int s) {
int i,n = p.size();
ll ans = 0;
bool ok[n] = {};
i = 0;
int cnt = 0;
while(cnt < n){
while(ok[i]){
i++;
ans++;
}
int fin = i;
ans += abs(p[i] - i);
i = p[i];
ok[i] = true;
cnt++;
while(i != fin){
ans += abs(p[i] - i);
i = p[i];
ok[i] = true;
cnt++;
}
}
ans += i;
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... |