Submission #380548

# Submission time Handle Problem Language Result Execution time Memory
380548 2021-03-22T09:11:36 Z hoaphat1 Aliens (IOI16_aliens) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
 
using namespace std;

long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
	vector<pair<int,int>> a;
	for (int i = 0; i < n; i++) {
		if (r[i] < c[i]) swap(r[i], c[i]);
		a.emplace_back(r[i], c[i]);
	}
	sort(a.begin(), a.end());
	vector<pair<int,int>> b;
	for (int i = 0; i < n; i++) {
		while (!b.empty() && b.back().second >= a[i].second) b.pop_back();
		b.push_back(a[i]);
	}
	swap(a, b);
	n = (int) a.size();
	auto test = [&](long long c) {
		const long long inf = 1e18;
		vector<pair<long long, int>> dp(n + 1, make_pair(inf, 0));
		dp[0] = {0, 0};
		for (int j = 1; j <= n; j++) {
			for (int from = j; from > 0; from--) {
				long long pre = (from > 1 ? a[from - 2].first : 0);
				if (pre >= a[from - 1].second) pre = (pre - a[from - 1].second + 1) * (pre - a[from - 1].second + 1);
				else pre = 0;
				dp[j] = min(dp[j], {dp[from - 1].first + 1ll * (a[j - 1].first - a[from - 1].second + 1) * (a[j - 1].first - a[from - 1].second + 1) + c - pre, dp[from - 1].second + 1});
			}
		}
		return dp[n];
	};
	long long l = 0, R = 1ll * m * m, ans = -1;
	while (l <= R) {
		long long mid = l + R >> 1;
		if (test(mid).second <= k) {
			ans = mid;
			R = mid - 1;
		}
		else l = mid + 1;
	}
	assert(ans !=- 1);
	return test(ans).first - ans * k;
}
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << take_photos(2, 6, 2, {2, 3}, {3, 4});
}

Compilation message

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:35:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |   long long mid = l + R >> 1;
      |                   ~~^~~
/tmp/cc41qDQD.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc0erdgF.o:aliens.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status