답안 #1051322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051322 2024-08-10T04:30:17 Z pawned 전선 연결 (IOI17_wiring) C++17
0 / 100
1 ms 348 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;

#include "wiring.h"

ll min_total_length(vector<int> r_g, vector<int> b_g) {
	vi r, b;
	for (int x : r_g)
		r.pb(x);
	for (int x : b_g)
		b.pb(x);
	int N = r.size();
	int M = b.size();
	map<int, ll> dp;
	// dp[i][j]: min cost to connect first i red (exclusive)
	// with first j blue (exclusive)
	dp[0] = 0;
	for (int i = 1; i <= N; i++) {
		map<int, ll> newdp;
		for (int j = max(i - 10, 1); j <= min(i + 10, M); j++) {
			newdp[j] = 1e18;
			if (newdp.find(j - 1) != dp.end())
				newdp[j] = min(newdp[j], newdp[j - 1] + abs(r[i - 1] - b[j - 1]));
			if (dp.find(j) != dp.end())
				newdp[j] = min(newdp[j], dp[j] + abs(r[i - 1] - b[j - 1]));
			if (dp.find(j - 1) != dp.end())
				newdp[j] = min(newdp[j], dp[j - 1] + abs(r[i - 1] - b[j - 1]));
		}
		dp = newdp;
	}
	return dp[M];
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '25859', found: '21828'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '904', found: '213'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB 3rd lines differ - on the 1st token, expected: '316', found: '188'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '27', found: '19'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '25859', found: '21828'
2 Halted 0 ms 0 KB -