Submission #1239249

#TimeUsernameProblemLanguageResultExecution timeMemory
1239249mychecksedad전선 연결 (IOI17_wiring)C++20
13 / 100
19 ms4936 KiB
#include "wiring.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define ll long long int
#define all(x) x.begin(),x.end()
const int N = 250;

ll dp[N][N];
long long min_total_length(std::vector<int> R, std::vector<int> B) {
	vector<ll> r(all(R));
	vector<ll> b(all(B));
	int n = r.size();
	int m = b.size();
	

	if(n < m) swap(n, m), swap(r, b);

	vector<pair<ll, int>> dp(n);

	dp[0] = {abs(r[0] - b[0]), 0};
	for(int i = 1; i < n; ++i){
		dp[i] = {dp[i - 1].ff + abs(r[i] - b[dp[i - 1].ss]), dp[i - 1].ss};
		if(dp[i - 1].ss + 1 < m){
			ll nxt = dp[i - 1].ff + abs(r[i] - b[dp[i - 1].ss + 1]);
			if(dp[i].ff > nxt || n - i == m - dp[i - 1].ss - 1){
				dp[i] = {nxt, dp[i - 1].ss + 1};
			}
		}
	}


	return dp[n-1].ff;
}
#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...