Submission #1320210

#TimeUsernameProblemLanguageResultExecution timeMemory
1320210kasamchiWiring (IOI17_wiring)C++20
17 / 100
1096 ms5120 KiB
#include "wiring.h" #include <vector> using namespace std; long long min_total_length(vector<int> r, vector<int> b) { int N = r.size() + b.size(); int ridx = 0, bidx = 0; vector<pair<int, int>> v; while (ridx < r.size() || bidx < b.size()) { if (bidx == b.size()) { v.push_back(make_pair(r[ridx], 0)); ridx++; } else if (ridx == r.size()) { v.push_back(make_pair(b[bidx], 1)); bidx++; } else if (r[ridx] < b[bidx]) { v.push_back(make_pair(r[ridx], 0)); ridx++; } else { v.push_back(make_pair(b[bidx], 1)); bidx++; } } vector<long long> dp(N, (long long)1e18); for (int idx = 0; idx < N; ) { int clb = idx, crb = idx; while (crb < N && v[crb].second == v[clb].second) { crb++; } idx = crb; crb--; if (clb == 0) { continue; } int prb = clb - 1, plb = prb; while (plb >= 0 && v[plb].second == v[prb].second) { plb--; } plb++; for (int c = clb; c <= crb; c++) { for (int p = plb; p <= (plb == 0 ? plb : prb); p++) { int i = p, j = clb; long long cur = (plb == 0 ? 0 : min(dp[p - 1], dp[p])); while (i <= prb && j <= c) { cur += v[j].first - v[i].first; i++, j++; } while (i <= prb) { cur += v[clb].first - v[i].first; i++; } while (j <= c) { cur += v[j].first - v[prb].first; j++; } dp[c] = min(dp[c], cur); } } } return dp[N - 1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...