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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
#define ffor(i, a, b) for (ll i = (a); i < (b); i++)
#define fford(i, a, b) for (ll i = (a); i > (b); i--)
#define rep(i, n) ffor(i, 0, n)
#define forin(x, a) for (auto &x: a)
#define all(a) a.begin(), a.end()
long long min_total_length(std::vector<int> r, std::vector<int> b) {
vvll dp(r.size() + 1, vll(b.size() + 1, 1ll << 62));
dp[0][0] = 0;
ffor(tot, 2, r.size() + b.size() + 1) {
ffor(i, max(1ll, tot - (ll)b.size()), min(tot, (ll)r.size() + 1)) {
ll j = tot - i;
cerr << i << ' ' << j << '\n';
ll curr = 0;
rep(k, i) {
curr += abs(r[i - k - 1] - b[j - 1]);
dp[i][j] = min(dp[i][j], dp[i - k - 1][j - 1] + curr);
}
curr = 0;
rep(k, j) {
curr += abs(r[i - 1] - b[j - k - 1]);
dp[i][j] = min(dp[i][j], dp[i - 1][j - k - 1] + curr);
}
}
}
return dp.back().back();
}
Compilation message (stderr)
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:18:42: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | #define ffor(i, a, b) for (ll i = (a); i < (b); i++)
| ^
wiring.cpp:27:2: note: in expansion of macro 'ffor'
27 | ffor(tot, 2, r.size() + b.size() + 1) {
| ^~~~
# | 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... |