# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
805051 | 2023-08-03T12:39:44 Z | Ellinor | 고대 책들 (IOI17_books) | C++14 | 105 ms | 14188 KB |
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int i = (a); i < (b); i++) #define pb push_back typedef long long ll; typedef pair<int, int> pii; #include "books.h" long long minimum_walk(std::vector<int> p, int s) { cerr << "hi " << s << "\n"; int cycles = 0; vector<int> cycle(p.size(), -1); vector<pii> lohi; ll base = 0; rep(i,0,p.size()) { if (p[i] == i) cycle[i] = -1; else if (cycle[i] == -1) { cycle[i] = cycles; base += abs(i - p[i]); int at = p[i], low = i, high = i; while (at != i) { if (at < low) low = at; if (at > high) high = at; base += abs(at - p[at]); cycle[at] = cycles; at = p[at]; } lohi.pb(make_pair(low, high)); cycles++; } } ll add = 0; if (s == 0) { int low = 0, high = 0; // inc //int ind = 0; rep(i,0,cycle.size()) { if (cycle[i] == -1) continue; if (i > high) add += (i - high) * 2; high = max(high, lohi[cycle[i]].second); } } else { cerr << "else\n"; vector<int> closest(cycle.size(), -1); if (cycle[0] == -1) closest[0] = -1; else closest[0] = 0; rep(i,1,s) { if (cycle[i] == -1) closest[i] = closest[i - 1]; else closest[i] = i; } if (cycle[cycle.size() - 1] == -1) closest[cycle.size() - 1] = -1; else closest[cycle.size() - 1] = cycle.size() - 1; for (int i = cycle.size() - 2; i > s; i--) // -2 !! { if (cycle[i] == -1) closest[i] = closest[i + 1]; else closest[i] = i; } cerr << "closest: "; rep(i,0,closest.size()) { cerr << closest[i] << " "; } cerr << "\n"; // edges int low = s, high = s; if (cycle[s] != -1) { low = lohi[cycle[s]].first; high = lohi[cycle[s]].second; } while (low > 0 || high < cycle.size() - 1) { int go; if (low > 0 && high < cycle.size() - 1) { if (closest[low - 1] == -1) { low = 0; continue; } if (closest[high + 1] == -1) { high = cycle.size() - 1; continue; } if (low - closest[low - 1] < closest[high + 1] - high) { go = closest[low - 1]; add += (low - closest[low - 1]) * 2; } else { go = closest[high + 1]; add += (closest[high + 1] - high) * 2; } } else if (high < cycle.size() - 1) { if (closest[high + 1] == -1) { high = cycle.size() - 1; continue; } go = closest[high + 1]; add += (closest[high + 1] - high) * 2; } else // low > 0 { if (closest[low - 1] == -1) { low = 0; continue; } go = closest[low - 1]; add += (low - closest[low - 1]) * 2; cerr << "add add " << low << " " << closest[low - 1] << " " << (low - closest[low - 1]) * 2 << "\n"; } low = min(low, lohi[cycle[go]].first); high = max(high, lohi[cycle[go]].second); } } ll ans = base + add; cerr << ans << "\n"; return ans; }
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 | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 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 | 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 | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 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 | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 0 ms | 212 KB | Output is correct |
23 | Correct | 0 ms | 212 KB | Output is correct |
24 | Correct | 0 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 0 ms | 212 KB | Output is correct |
29 | Correct | 0 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 | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 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 | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 0 ms | 212 KB | Output is correct |
23 | Correct | 0 ms | 212 KB | Output is correct |
24 | Correct | 0 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 0 ms | 212 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 96 ms | 12012 KB | Output is correct |
31 | Correct | 93 ms | 12012 KB | Output is correct |
32 | Correct | 69 ms | 12016 KB | Output is correct |
33 | Correct | 79 ms | 14172 KB | Output is correct |
34 | Correct | 79 ms | 14180 KB | Output is correct |
35 | Correct | 105 ms | 14176 KB | Output is correct |
36 | Correct | 81 ms | 14188 KB | Output is correct |
37 | Correct | 86 ms | 12396 KB | Output is correct |
38 | Correct | 79 ms | 12136 KB | Output is correct |
39 | Correct | 77 ms | 12136 KB | Output is correct |
40 | Correct | 80 ms | 12008 KB | Output is correct |
41 | Correct | 95 ms | 12012 KB | Output is correct |
42 | Correct | 93 ms | 12044 KB | Output is correct |
43 | Correct | 98 ms | 14188 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '3334' |
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 | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 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 | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 0 ms | 212 KB | Output is correct |
23 | Correct | 0 ms | 212 KB | Output is correct |
24 | Correct | 0 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 0 ms | 212 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 96 ms | 12012 KB | Output is correct |
31 | Correct | 93 ms | 12012 KB | Output is correct |
32 | Correct | 69 ms | 12016 KB | Output is correct |
33 | Correct | 79 ms | 14172 KB | Output is correct |
34 | Correct | 79 ms | 14180 KB | Output is correct |
35 | Correct | 105 ms | 14176 KB | Output is correct |
36 | Correct | 81 ms | 14188 KB | Output is correct |
37 | Correct | 86 ms | 12396 KB | Output is correct |
38 | Correct | 79 ms | 12136 KB | Output is correct |
39 | Correct | 77 ms | 12136 KB | Output is correct |
40 | Correct | 80 ms | 12008 KB | Output is correct |
41 | Correct | 95 ms | 12012 KB | Output is correct |
42 | Correct | 93 ms | 12044 KB | Output is correct |
43 | Correct | 98 ms | 14188 KB | Output is correct |
44 | Incorrect | 3 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '3334' |
45 | Halted | 0 ms | 0 KB | - |