# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
826462 | 2023-08-15T15:33:46 Z | caganyanmaz | Wiring (IOI17_wiring) | C++17 | 796 ms | 5460 KB |
#include <bits/stdc++.h> #define pb push_back #define int int64_t using namespace std; #include "wiring.h" #ifdef DEBUGGING #include "../debug.h" #else #define debug(x...) void(42) #endif constexpr static int MXN = 1e5; #ifdef DEBUGGING constexpr static int MXG = 10; #else constexpr static int MXG = 205; #endif constexpr static int INF = 1e10; deque<int> r, b; long long subtask2() { int m = r.back(); int sum = 0; for (int i : r) sum += m - i; for (int i : b) sum += i - m; if (r.size() > b.size()) sum += (b[0] - m) * (r.size() - b.size()); return sum; } vector<int> dp(MXG); vector<int> dp2(MXG); long long min_total_length(vector<int32_t> rr, vector<int32_t> bb) { for (int i : rr) r.push_back(i); for (int i : bb) b.push_back(i); if (r.back() < b[0]) return subtask2(); int g = 200; if (rr.size() > 200 || bb.size() > 200) g = 9; int current = 0; fill(dp.begin(), dp.begin() + g, INF); dp[0] = 0; if (r[0] > b[0]) swap(r, b); int mnr = -INF; while (r.size() || b.size()) { vector<int> v; assert(v.size() < g); while (r.size() && (b.empty() || r[0] < b[0])) { v.pb(r[0]); r.pop_front(); } fill(dp2.begin(), dp2.begin() + g, INF); int rb = b[0], lb = v[0]; for (int i = 0; i <= v.size(); i++) // How many we're putting to right { int lsum = 0; int rsum = 0; for (int j = 0; j < v.size()-i; j++) lsum += v[j] - lb; for (int j = v.size()-i; j < v.size(); j++) rsum += rb - v[j]; for (int j = 0; j < g; j++) // How many is coming from right { if (j < v.size()-i) // We need to take more dp2[i] = min<int>(dp2[i], dp[j] + (v.size()-i-j) * (lb - mnr) + lsum + rsum); else dp2[i] = min<int>(dp2[i], dp[j] + lsum + rsum); // We might need to give more as well (but it has 0 contribution so it doesn't matter) } } for (int i = 0; i < g; i++) dp[i] = dp2[i]; mnr = v.back(); swap(r, b); } return dp[0]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 304 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 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 | 308 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 268 KB | Output is correct |
3 | Correct | 14 ms | 3440 KB | Output is correct |
4 | Correct | 14 ms | 3252 KB | Output is correct |
5 | Correct | 15 ms | 3212 KB | Output is correct |
6 | Correct | 19 ms | 4428 KB | Output is correct |
7 | Correct | 21 ms | 4324 KB | Output is correct |
8 | Correct | 19 ms | 4264 KB | Output is correct |
9 | Correct | 19 ms | 4464 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 304 KB | Output is correct |
3 | Correct | 32 ms | 4764 KB | Output is correct |
4 | Correct | 28 ms | 5036 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 300 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 300 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 308 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 28 ms | 5416 KB | Output is correct |
19 | Correct | 28 ms | 5324 KB | Output is correct |
20 | Correct | 26 ms | 5460 KB | Output is correct |
21 | Correct | 29 ms | 5432 KB | Output is correct |
22 | Correct | 28 ms | 5424 KB | Output is correct |
23 | Correct | 28 ms | 5416 KB | Output is correct |
24 | Correct | 28 ms | 5332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 796 ms | 4872 KB | secret mismatch |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 304 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 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 | 308 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 1 ms | 268 KB | Output is correct |
19 | Correct | 14 ms | 3440 KB | Output is correct |
20 | Correct | 14 ms | 3252 KB | Output is correct |
21 | Correct | 15 ms | 3212 KB | Output is correct |
22 | Correct | 19 ms | 4428 KB | Output is correct |
23 | Correct | 21 ms | 4324 KB | Output is correct |
24 | Correct | 19 ms | 4264 KB | Output is correct |
25 | Correct | 19 ms | 4464 KB | Output is correct |
26 | Correct | 0 ms | 212 KB | Output is correct |
27 | Correct | 0 ms | 304 KB | Output is correct |
28 | Correct | 32 ms | 4764 KB | Output is correct |
29 | Correct | 28 ms | 5036 KB | Output is correct |
30 | Correct | 0 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 300 KB | Output is correct |
32 | Correct | 0 ms | 212 KB | Output is correct |
33 | Correct | 0 ms | 212 KB | Output is correct |
34 | Correct | 1 ms | 300 KB | Output is correct |
35 | Correct | 0 ms | 212 KB | Output is correct |
36 | Correct | 0 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
38 | Correct | 1 ms | 308 KB | Output is correct |
39 | Correct | 1 ms | 212 KB | Output is correct |
40 | Correct | 0 ms | 212 KB | Output is correct |
41 | Correct | 1 ms | 212 KB | Output is correct |
42 | Correct | 1 ms | 212 KB | Output is correct |
43 | Correct | 28 ms | 5416 KB | Output is correct |
44 | Correct | 28 ms | 5324 KB | Output is correct |
45 | Correct | 26 ms | 5460 KB | Output is correct |
46 | Correct | 29 ms | 5432 KB | Output is correct |
47 | Correct | 28 ms | 5424 KB | Output is correct |
48 | Correct | 28 ms | 5416 KB | Output is correct |
49 | Correct | 28 ms | 5332 KB | Output is correct |
50 | Correct | 0 ms | 212 KB | Output is correct |
51 | Incorrect | 796 ms | 4872 KB | secret mismatch |
52 | Halted | 0 ms | 0 KB | - |