제출 #425811

#제출 시각아이디문제언어결과실행 시간메모리
425811Hazem전선 연결 (IOI17_wiring)C++14
0 / 100
1 ms204 KiB
#include "wiring.h"
#include <bits/stdc++.h>

using namespace std;

#define LL long long

const LL INF  = 1e9;
const LL LINF = 1e18;
const int N = 2e3+10;

LL dp[N][N][2][2];
int n,m;
vector<int>R,B;

LL solve(int i,int j,int t1,int t2){
	
	if(i==n-1&&j==m-1&&t1&&t2)
		return 0;
	
	if(dp[i][j][t1][t2]!=-1)
		return dp[i][j][t1][t2];
	
	dp[i][j][t1][t2] = LINF;
	if(t1&&i<n-1)
		dp[i][j][t1][t2] = min(dp[i][j][t1][t2],solve(i+1,j,0,t2));
	if(t2&&j<m-1)
		dp[i][j][t1][t2] = min(dp[i][j][t1][t2],solve(i,j+1,t1,0));
		
	dp[i][j][t1][t2] = min(dp[i][j][t1][t2],solve(i,j,1,1)+abs(R[i]-B[j]));
	return dp[i][j][t1][t2];
}

long long min_total_length(std::vector<int> r, std::vector<int> b) {

	n = r.size(),m = b.size();
	for(auto x:r)
		R.push_back(x);
	for(auto x:b)
		B.push_back(x);

	LL sum1 = 0,sum2 = 0;
	
	for(auto x:R)
		sum1 += 0ll+x;
	
	for(auto x:B)
		sum2 += 0ll+x;
	
	LL ret = 1ll*sum2-R.back()*m + 1ll*B.front()*n-sum1;
	ret -= B[0]-R[n-1];
	if(n>1&&m>1)
		ret -= (B[0]-R[n-1]);
		
	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...