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>
using namespace std;
#define int long long
#define F first
#define S second
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
int min_total_length(vector<signed> r, vector<signed> b)
{
int res = 0;
int n = r.size() + b.size();
vector<pair<int, int>> a;
for (int i = 0; i < r.size(); i++)
a.push_back({ r[i], 0 });
for (int i = 0; i < b.size(); i++)
a.push_back({ b[i], 1 });
sort(a.begin(), a.end());
viii dp(n + 1, vii(r.size() + 2, vi(b.size() + 2, 1e18)));
dp[0][0][0] = 0;
int lst = 0;
int lstr, lstb;
lstr = lstb = -1e18;
for (int i = 0; i < n; i++) {
int d = a[i].F - lst;
if (a[i].S == 0)
lstr = a[i].F;
else
lstb = a[i].F;
for (int j = 0; j <= r.size(); j++) {
for (int k = 0; k <= b.size(); k++) {
if (a[i].S == 0) {
dp[i + 1][j][k] = min(dp[i][j][k] + (d * (j + k)) + (a[i].F - lstb), min(dp[i][j][k + 1] + (d * (j + k + 1)), (j > 0 ? dp[i][j - 1][k] + (d * (j + k - 1)) : (int)1e18)));
} else {
dp[i + 1][j][k] = min(dp[i][j][k] + (d * (j + k)) + (a[i].F - lstr), min(dp[i][j + 1][k] + (d * (j + k + 1)), (k > 0 ? dp[i][j][k - 1] + (d * (j + k - 1)) : (int)1e18)));
}
//cout << dp[i][j][k] << ' ';
}
//cout << endl;
}
//cout << endl
// << endl;
lst = a[i - 1].F;
}
return dp[n - 1][0][0];
}
Compilation message (stderr)
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:20:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i = 0; i < r.size(); i++)
| ~~^~~~~~~~~~
wiring.cpp:22:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < b.size(); i++)
| ~~^~~~~~~~~~
wiring.cpp:36:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int j = 0; j <= r.size(); j++) {
| ~~^~~~~~~~~~~
wiring.cpp:37:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int k = 0; k <= b.size(); k++) {
| ~~^~~~~~~~~~~
wiring.cpp:17:9: warning: unused variable 'res' [-Wunused-variable]
17 | int res = 0;
| ^~~
# | 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... |