Submission #42957

# Submission time Handle Problem Language Result Execution time Memory
42957 2018-03-06T21:23:00 Z alenam0161 Wiring (IOI17_wiring) C++14
0 / 100
2 ms 532 KB
#include "wiring.h"
#include <iostream>
#include <algorithm>
using namespace std;
vector<long long> pre, suf;
vector<pair<int, int>> all;
int n;
long long pre_gum(int l, int r) {
	if (l > r)return 0;
	if (l == 0) {
		return pre[r]-(r-l+1)*all[0].first;
	}
	return pre[r] -pre[l-1]- all[l].first * (r - l + 1);
}
long long suf_gum(int l, int r) {
	if (l > r)return 0;
	return suf[l] -suf[r+1]- (all[n-1].first-all[r].first) * (r-l+1);
}
long long sum(int l, int mid, int r) {
	return pre_gum(l, mid) + suf_gum(mid + 1, r) + max(mid - l + 1, r - mid)*(all[mid + 1].first - all[mid].first);
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
	for (int to : r)all.push_back({ to,1 });
	for (int to : b)all.push_back({ to,2 });
	int n = all.size();
	::n = n;
	sort(all.begin(), all.end());
	vector<int> left(n + 1, 0);
	for (int i = 0; i < n; ++i) {
		if (i == 0 || (all[i].second != all[i - 1].second)) {
			left[i] = i;
		}
		else left[i] = left[i - 1];
	}
	pre.resize(n + 5, 0);
	suf.resize(n + 5, 0);
	for (int i = 0; i < n; ++i) {
		pre[i] = (i == 0 ? 0 : pre[i - 1]) + all[i].first;
	}
	for (int i = n - 1; i >= 0;i--) {
		suf[i] = (i ==n-1? 0 : suf[i + 1]) +all[n-1].first-all[i].first;
	}
	vector<long long> dp(n + 5, (long long)1e18);
	for (int i = 0; i < n; ++i) {
		if (left[i] == 0)continue;
		long long mn = dp[i-1];
		int lf = left[i] - 1;
		mn = dp[lf];
		for (int j = left[lf]; j >= left[lf]; --j) {
			if (j == 0)mn = 0;
			else mn = min(mn, dp[j - 1]);
			dp[i] = min(dp[i], mn + sum(j, lf, i));
		}
	}
	return dp[n-1];
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB 3rd lines differ - on the 1st token, expected: '25859', found: '44504'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 480 KB 3rd lines differ - on the 1st token, expected: '904', found: '871'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 532 KB 3rd lines differ - on the 1st token, expected: '316', found: '338'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 532 KB 3rd lines differ - on the 1st token, expected: '27', found: '42'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB 3rd lines differ - on the 1st token, expected: '25859', found: '44504'
2 Halted 0 ms 0 KB -