Submission #91149

#TimeUsernameProblemLanguageResultExecution timeMemory
91149arman_ferdousWiring (IOI17_wiring)C++17
20 / 100
33 ms18484 KiB
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 1e5+10;
int n, m;
int r[N], b[N];

ll dp[205][205];

long long min_total_length(std::vector<int> r_, std::vector<int> b_) {
	n = r_.size(); m = b_.size();
	for(int i = 0; i < n; i++) r[i] = r_[i];
	for(int i = 0; i < m; i++) b[i] = b_[i];

	if(max(n,m) <= 200) {
		for(int i = 1; i < 205; i++)
			dp[0][i] = dp[i][0] = (ll)1e18;
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				dp[i][j] = abs(r[i-1] - b[j-1]) + min({dp[i-1][j], dp[i][j-1], dp[i-1][j-1]});
			}
		}
		return dp[n][m];
	}
	ll ret = 0;
	if(n <= m) {
		for(int i = 0; i < m; i++)
			ret += (b[i] - (i >= n ? r[n-1] : r[i]));
	}
	else {
		for(int i = n-1; i >= 0; i--)
			ret += ((i >= m ? b[0] : b[i]) - r[i]);
	}
	return ret;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...