# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
296907 | ASDF123 | Wiring (IOI17_wiring) | C++17 | 0 ms | 0 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 "grader.cpp"
#include <bits/stdc++.h>
#define szof(s) (int)s.size()
#define pii pair<int, int>
#define ll long long
#define fr first
#define sc second
using namespace std;
const int N = (int)2e5 + 5;
vector <int> g[N];
bool used[N];
struct Edge {
int u, v, len;
Edge(int u_, int v_, int len_) {
u = u_, v = v_, len = len_;
}
Edge () {
}
};
bool operator < (const Edge &a, const Edge &b) {
return a.len < b.len;
}
long long min_total_length(vector<int> r, vector<int> b) {
vector <Edge> edges;
for (int i = 0; i < szof(r); i++) {
for (int j = 0; j < szof(b); j++) {
int u = i + 1;
int v = szof(r) + j + 1;
edges.push_back(Edge(u, v, abs(r[i] - b[j])));
}
}
sort(edges.begin(), edges.end());
ll ans = 0;
for (Edge el : edges) {
if (!used[el.u] || !used[el.v]) {
used[el.u] = used[el.v] = 1;
ans += el.len;
}
}
return ans;
}