# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
822940 | Minindu206 | Wiring (IOI17_wiring) | C++14 | 1 ms | 340 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 ll long long
using namespace std;
long long min_total_length(std::vector<int> r, std::vector<int> b)
{
int n = r.size(), m = b.size();
if(n <= 200 && m <= 200)
{
ll ans = 0;
vector<int> visb(m, 0);
for(int i=0;i<n;i++)
{
int mn = -1, val = INT_MAX;
for(int j=0;j<m;j++)
{
if(visb[j])
continue;
int cur = abs(r[i] - b[j]);
if(cur < val)
mn = j, val = cur;
}
visb[mn] = 1;
ans += val;
}
for(int j=0;j<m;j++)
{
if(visb[j] == 1)
continue;
int mn = -1, val = INT_MAX;
for(int i=0;i<n;i++)
{
int cur = abs(r[i] - b[j]);
if(cur < val)
mn = i, val = cur;
}
ans += val;
}
return ans;
}
ll rmx = r[n - 1];
ll ans = 0;
for (int i = 0; i < m; i++)
ans += b[i] - rmx;
for (int i = 0; i < n - 1; i++)
ans += rmx - r[i];
ans += max((ll)(n - m) * (b[0] - rmx), 0LL);
return ans;
}
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... |