# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
49209 | MatheusLealV | 고대 책들 (IOI17_books) | C++17 | 3 ms | 812 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
#define N 1000005
using namespace std;
typedef long long ll;
int G[N], ok[N], cor, sz[N], C[N];
void dfs(int x)
{
if(ok[G[x]]) return;
ok[G[x]] = 1;
dfs(G[x]);
}
void co(int x)
{
if(C[G[x]]) return;
C[G[x]] = cor, sz[cor] ++;
co(G[x]);
}
ll minimum_walk(vector<int> p, int s)
{
ll ans = 0;
for(int i = 0; i < p.size(); i++) G[i] = p[i], ans += abs(i - p[i]);
for(int i = 0; i < p.size(); i++)
{
if(C[i]) continue;
++cor;
C[i] = cor;
sz[cor] = 1;
co(i);
}
while(s >= 0)
{
dfs(s);
int prox = -1, d = 2000000000;
for(int i = 0; i < p.size(); i++)
{
if(ok[i] || sz[C[i]] <= 1) continue;
if(abs(s - i) < d)
{
d = abs(s - i);
prox = i;
}
}
if(prox == -1) ans += s;
else ans += d;
s = prox;
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |