Submission #789276

#TimeUsernameProblemLanguageResultExecution timeMemory
789276Sohsoh84Aliens (IOI16_aliens)C++17
25 / 100
74 ms8308 KiB
#include "aliens.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define all(x)			(x).begin(), (x).end()
#define sep			' '
#define debug(x)		cerr << #x << ": " << x << endl;

const ll MAXN = 1000 + 10;

int n, m, k;
ll dp[MAXN][MAXN], f[MAXN];

inline ll pw(ll a) {
	return a * a;
}

inline ll calc() {
	vector<int> opts;
	ll mx_f = -1;
	for (int i = 0; i < m; i++) {
		if (f[i] > mx_f) {
			mx_f = f[i];
			opts.push_back(i);
		}
	}

	for (int e : opts) {
		int len = f[e] - e + 1;
		dp[e][1] = pw(len + e - opts.front());
		for (int ii = 0; ii < int(opts.size()); ii++) {
			int e2 = opts[ii];
			if (e2 >= e) break;
		
			int tlen = len + (e - opts[ii + 1]);
			int mn_cov = opts[ii + 1];
			for (int j = 1; j <= k; j++) {
				dp[e][j] = min(dp[e][j], dp[e2][j - 1] + pw(tlen) - (mn_cov > f[e2] ? 0 : pw(f[e2] - mn_cov + 1)));
			}
		}
	}

	ll ans = numeric_limits<ll>::max();
	for (int j = 1; j <= k; j++)
		ans = min(ans, dp[opts.back()][j]);

	return ans;
}

ll take_photos(int n_, int m_, int k_, vector<int> r, vector<int> c) {
	fill(f, f + MAXN, -1);
	memset(dp, 63, sizeof dp);

	n = n_, m = m_, k = k_;
	for (int i = 0; i < n; i++) {
		int x = r[i], y = c[i];
		if (y < x) swap(x, y); // TODO: check
		f[x] = max(f[x], ll(y));
	}

	return calc();
}
#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...