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 <cmath>
#include <iostream>
using namespace std;
//#define int long long
const int MAX_POINT = 200 + 2;
const int INF = 1e9 + 7;
int nbRouge, nbBleu;
long long dp[MAX_POINT][MAX_POINT];
vector<pair<int, int> > position;
long long min_total_length(std::vector<int> r, std::vector<int> b)
{
nbRouge = (int)r.size();
nbBleu = (int)b.size();
for(int curRouge = 0; curRouge <= nbRouge; curRouge++)
{
for(int curBleu = 0; curBleu <= nbBleu; curBleu++)
{
dp[curRouge][curBleu] = INF;
}
}
dp[0][0] = 0;
for(int curRouge = 0; curRouge <= nbRouge; curRouge++)
{
for(int curBleu = 0; curBleu <= nbBleu; curBleu++)
{
//cout << curRouge << " " << curBleu << " " << dp[curRouge][curBleu] << endl;
if(curBleu != 0)
{
dp[curRouge + 1][curBleu] = min(dp[curRouge + 1][curBleu], dp[curRouge][curBleu] + abs(r[curRouge] - b[curBleu - 1]));
}
if(curRouge != 0)
{
dp[curRouge][curBleu + 1] = min(dp[curRouge][curBleu + 1], dp[curRouge][curBleu] + abs(r[curRouge - 1] - b[curBleu]));
}
dp[curRouge + 1][curBleu + 1] = min(dp[curRouge + 1][curBleu + 1], dp[curRouge][curBleu] + abs(r[curRouge] - b[curBleu]));
}
}
return dp[nbRouge][nbBleu];
}
# | 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... |