# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
542829 | 2022-03-28T07:29:36 Z | zggf | 고대 책들 (IOI17_books) | C++14 | 191 ms | 28800 KB |
#include "books.h" #include <bits/stdc++.h> using namespace std; vector<int> parent, ranga; int find(int x){ if(parent[x]==-1) return x; parent[x] = find(parent[x]); return parent[x]; } void join(int a, int b){ a = find(a); b = find(b); if(a==b) return; if(ranga[a]>ranga[b]){ parent[b] = a; }else if(ranga[b]>ranga[a]){ parent[a] = b; }else{ parent[b] = a; ranga[a]++; } } long long minimum_walk(std::vector<int> p, int s) { int n = p.size(); vector<int> odw(n); parent.resize(n, -1); ranga.resize(n); long long wyn = 0; vector<pair<int, int>> inp; for(int i = 0; i < n; i++){ int pt = i; if(!odw[pt]){ if(p[pt]!=pt){ int mini = 1e9; int maxi = -1e9; while(!odw[pt]){ mini = min(mini, pt); maxi = max(maxi, pt); odw[pt] = true; wyn+=abs(p[pt]-pt); pt = p[pt]; } inp.push_back({mini, maxi}); }else{ odw[pt] = true; } } } inp.push_back({s, s}); sort(inp.begin(), inp.end()); int dal = 0; for(int i = 0; i < inp.size()-1; i++){ dal = max(dal, inp[i].second); while(inp[i+1].first<dal){ i++; dal = max(dal, inp[i].second); if(i==inp.size()-1) break; } if(i<inp.size()-1){ wyn+=2*(inp[i+1].first-dal); } } return wyn; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 308 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 300 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 308 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 300 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 300 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 1 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 1 ms | 212 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 308 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 300 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 300 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 1 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 1 ms | 212 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 153 ms | 26616 KB | Output is correct |
31 | Correct | 191 ms | 26616 KB | Output is correct |
32 | Correct | 123 ms | 26600 KB | Output is correct |
33 | Correct | 129 ms | 28760 KB | Output is correct |
34 | Correct | 135 ms | 28764 KB | Output is correct |
35 | Correct | 164 ms | 28764 KB | Output is correct |
36 | Correct | 133 ms | 28800 KB | Output is correct |
37 | Correct | 112 ms | 26988 KB | Output is correct |
38 | Correct | 120 ms | 26604 KB | Output is correct |
39 | Correct | 153 ms | 26596 KB | Output is correct |
40 | Correct | 118 ms | 26584 KB | Output is correct |
41 | Correct | 131 ms | 26572 KB | Output is correct |
42 | Correct | 133 ms | 26604 KB | Output is correct |
43 | Correct | 168 ms | 28756 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 308 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 300 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 300 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 1 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 1 ms | 212 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 153 ms | 26616 KB | Output is correct |
31 | Correct | 191 ms | 26616 KB | Output is correct |
32 | Correct | 123 ms | 26600 KB | Output is correct |
33 | Correct | 129 ms | 28760 KB | Output is correct |
34 | Correct | 135 ms | 28764 KB | Output is correct |
35 | Correct | 164 ms | 28764 KB | Output is correct |
36 | Correct | 133 ms | 28800 KB | Output is correct |
37 | Correct | 112 ms | 26988 KB | Output is correct |
38 | Correct | 120 ms | 26604 KB | Output is correct |
39 | Correct | 153 ms | 26596 KB | Output is correct |
40 | Correct | 118 ms | 26584 KB | Output is correct |
41 | Correct | 131 ms | 26572 KB | Output is correct |
42 | Correct | 133 ms | 26604 KB | Output is correct |
43 | Correct | 168 ms | 28756 KB | Output is correct |
44 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
45 | Halted | 0 ms | 0 KB | - |