# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1035417 | 2024-07-26T10:37:41 Z | 0npata | Wiring (IOI17_wiring) | C++17 | 1000 ms | 12292 KB |
#include "wiring.h" #include<bits/stdc++.h> using namespace std; #define vec vector #define int long long const int INF = 1e18; long long min_total_length(std::vector<int32_t> r, std::vector<int32_t> b) { vec<vec<int>> v(0); int n = r.size(); int m = b.size(); int lst = -1; { int i = 0; int j = 0; while(i+j < n+m) { if(i == n || (j<m && b[j] < r[i])) { if(lst != 0) { lst = 0; v.push_back({}); } v.back().push_back(b[j]); j++; } else { if(lst != 1) { lst = 1; v.push_back({}); } v.back().push_back(r[i]); i++; } } } vec<vec<int>> dp(v.size()); dp[0] = vec<int>(v[0].size()+1, INF); dp[0][0] = 0; for(int i = 1; i<v.size(); i++) { dp[i] = vec<int>(v[i].size()+1, INF); int k = v[i-1].size()-1; dp[i][0] = dp[i-1].back(); int asum = 0; int bsum = v[i-1][k]; for(int j = 1; j<=v[i].size(); j++) { auto eval = [&]() { int psz = v[i-1].size()-k; return (asum - bsum) + max(j - psz, 0ll) * (-v[i-1].back()) + max(psz - j, 0ll) * v[i][0] + min(dp[i-1][k], dp[i-1][k+1]); }; asum += v[i][j-1]; k = v[i-1].size(); bsum = 0; while(k > 0) { //int cur = eval(); k--; bsum += v[i-1][k]; int cur = 0; dp[i][j] = min(dp[i][j], eval()); //cerr << eval() << ' '; int nxt = eval(); if(nxt > cur && i > 1 && false) { bsum -= v[i-1][k]; k++; break; } } //cerr << '\n'; //dp[i][j] = eval(); //cerr << k << ' ' << dp[i][j] << ' '; } //cerr << '\n'; } return dp.back().back(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 344 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 604 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 436 KB | Output is correct |
12 | Correct | 1 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 344 KB | Output is correct |
15 | Correct | 0 ms | 436 KB | Output is correct |
16 | Correct | 1 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Execution timed out | 1082 ms | 5476 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 28 ms | 12044 KB | Output is correct |
4 | Correct | 25 ms | 9744 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 344 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 344 KB | Output is correct |
15 | Correct | 0 ms | 344 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Correct | 28 ms | 12136 KB | Output is correct |
19 | Correct | 28 ms | 12036 KB | Output is correct |
20 | Correct | 25 ms | 10044 KB | Output is correct |
21 | Correct | 32 ms | 12292 KB | Output is correct |
22 | Correct | 28 ms | 11528 KB | Output is correct |
23 | Correct | 28 ms | 11520 KB | Output is correct |
24 | Correct | 30 ms | 11524 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Execution timed out | 1087 ms | 5688 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 344 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 604 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 436 KB | Output is correct |
12 | Correct | 1 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 344 KB | Output is correct |
15 | Correct | 0 ms | 436 KB | Output is correct |
16 | Correct | 1 ms | 344 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Execution timed out | 1082 ms | 5476 KB | Time limit exceeded |
20 | Halted | 0 ms | 0 KB | - |