# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
838030 | Kerim | Wiring (IOI17_wiring) | C++17 | 1081 ms | 7108 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "wiring.h"
#include "bits/stdc++.h"
#define ff first
#define ss second
#define ll long long
using namespace std;
const ll B = 1e16;
void make(vector<ll>&v, int sz){
v.resize(sz);
for (int i = 0; i < sz; i++)
v[i] = B;
}
ll min_total_length(vector<int> r, vector<int> b) {
vector<pair<int,int> > v;
vector<vector<int> > d;
vector<int> sz;
for (auto x: r) v.push_back({x, 0});
for (auto x: b) v.push_back({x, 1});
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++){
int j = i;
vector<int> g{-1};
while (j < v.size() and v[i].ss == v[j].ss)
g.push_back(v[j++].ff);
d.push_back(g);
sz.push_back(j - i);
i = j - 1;
}
int n = d.size();
vector<ll> dp, odp;
make(dp, sz[0]+1);
dp[0] = 0;
for (int i = 1; i < n; i++){
swap(odp, dp);
make(dp, sz[i]+1);
dp[0] = odp[sz[i-1]];
for (int j = 1; j <= sz[i]; j++)
for (int k = 1; k <= sz[i-1]; k++){
ll cost = (d[i][1] - d[i-1][sz[i-1]])*1LL*max(j, (sz[i-1] - k + 1));
for (int h = k; h <= sz[i-1]; h++) cost += d[i-1][sz[i-1]] - d[i-1][h];
for (int h = 1; h <= j; h++) cost += d[i][h] - d[i][1];
dp[j] = min(dp[j], min(odp[k-1], odp[k]) + cost);
}
}
return dp[sz[n-1]];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |