Submission #826352

#TimeUsernameProblemLanguageResultExecution timeMemory
826352tolbiWiring (IOI17_wiring)C++17
7 / 100
108 ms262144 KiB
#include <bits/stdc++.h>
using namespace std;
#include "wiring.h"

long long ara(long long a, long long b){
	if (a>b) return a-b;
	return b-a;
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
	int n = r.size();
	int m = b.size();
	vector<vector<long long>> dp(n, vector<long long>(m,-1));
	function<long long(int,int)> f;
	f = [&](int x, int y)->long long{
		if (dp[x][y]!=-1) return dp[x][y];
		if (x==n-1 && y==m-1){
			return ara(r[x],b[y]);
		}
		if (x==n-1){
			return dp[x][y]=ara(r[x],b[y])+f(x,y+1);
		}
		if (y==m-1){
			return dp[x][y]=ara(r[x],b[y])+f(x+1,y);
		}
		dp[x][y]=ara(r[x],b[y]);
		long long mava = f(x+1,y+1);
		mava=min(mava,f(x,y+1));
		mava=min(mava,f(x+1,y));
		return dp[x][y]+=mava;
	};
	return f(0,0);
}
#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...