제출 #712295

#제출 시각아이디문제언어결과실행 시간메모리
712295SanguineChameleonAliens (IOI16_aliens)C++17
0 / 100
1 ms212 KiB
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 20;
const long long inf = 1e18L + 20;
const long long max_cost = 1e12L + 20;
int lt[maxn];
int rt[maxn];
long long over[maxn];
pair<long long, int> dp[maxn];
long long cost;
int n;

void solve() {
	dp[0] = {0, 0};
	for (int i = 1; i <= n; i++) {
		dp[i] = {inf, -1};
		for (int j = 0; j < i; j++) {
			dp[i] = min(dp[i], {dp[j].first + 1LL * (rt[i] - lt[j + 1] + 1) * (rt[i] - lt[j + 1] + 1) - over[j] + cost, dp[j].second + 1});
		}
	}
}

long long take_photos(int _n, int m, int k, std::vector<int> rows, std::vector<int> cols) {
	n = _n;
	vector<pair<int, int>> p, q;
	for (int i = 0; i < n; i++) {
		if (rows[i] > cols[i]) {
			swap(rows[i], cols[i]);
		}
		p.push_back({rows[i], -cols[i]});
	}
	sort(p.begin(), p.end());
	for (auto x: p) {
		if (q.empty() || x.second < q.back().second) {
			q.push_back(x);
		}
	}
	n = q.size();
	k = min(k, n);
	for (int i = 0; i < n; i++) {
		lt[i + 1] = q[i].first;
		rt[i + 1] = -q[i].second;
	}
	over[0] = 0;
	for (int i = 1; i <= n - 1; i++) {
		int sz = max(rt[i] - lt[i + 1] + 1, 0);
		over[i] = 1LL * sz * sz;
	}
	long long cost_l = 0;
	long long cost_r = max_cost;
	long long res = inf;
	while (cost_l <= cost_r) {
		cost = (cost_l + cost_r) / 2;
		solve();
		if (dp[n].second <= k) {
			res = min(res, dp[n].first - cost * k);
			cost_r = cost - 1;
		}
		else {
			cost_l = cost + 1;
		}
	}
	return res;
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...