# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
49209 | 2018-05-23T19:07:59 Z | MatheusLealV | 고대 책들 (IOI17_books) | C++17 | 3 ms | 812 KB |
#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; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 588 KB | Output is correct |
4 | Correct | 2 ms | 588 KB | Output is correct |
5 | Correct | 2 ms | 588 KB | Output is correct |
6 | Incorrect | 3 ms | 812 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 588 KB | Output is correct |
4 | Correct | 2 ms | 588 KB | Output is correct |
5 | Correct | 2 ms | 588 KB | Output is correct |
6 | Incorrect | 3 ms | 812 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 588 KB | Output is correct |
4 | Correct | 2 ms | 588 KB | Output is correct |
5 | Correct | 2 ms | 588 KB | Output is correct |
6 | Incorrect | 3 ms | 812 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 812 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '5157' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 588 KB | Output is correct |
4 | Correct | 2 ms | 588 KB | Output is correct |
5 | Correct | 2 ms | 588 KB | Output is correct |
6 | Incorrect | 3 ms | 812 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |