Submission #394065

# Submission time Handle Problem Language Result Execution time Memory
394065 2021-04-25T10:12:28 Z Drew_ Aliens (IOI16_aliens) C++14
0 / 100
1 ms 204 KB
#include "aliens.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;

#define ll long long
#define pb push_back
#define ii pair<int, int>
#define pl pair<ll, ll>
#define f1 first
#define s2 second

const int MAX = 1e5 + 7;

vector<ii> interval;

//cost for interval [i, j], assuming interval [0, i-1] have been fulfilled
inline ll getCost(int i, int j)
{
	ll res = 1LL * (interval[j].s2 - interval[i].f1 + 1) * (interval[j].s2 - interval[i].f1 + 1);
	if (i)
	{
		if (interval[i-1].s2 >= interval[i].f1)
			res -= 1LL * (interval[i-1].s2 - interval[i].f1 + 1) * (interval[i-1].s2 - interval[i].f1 + 1);
	}
	return res;
}

ll dp[MAX];
int ctr[MAX];

pl check(int slope)
{
	dp[0] = ctr[0] = 0;

	dp[1] = min(0LL, getCost(0, 0) - slope);
	ctr[1] = 1;

	for (int i = 2; i <= interval.size(); ++i)
	{
		int l = 0, r = i-2;
		while (l < r)
		{
			int mid = (l + r) / 2;
			if (getCost(mid, i) >= slope) r = mid;
			else l = mid + 1;
		}
		dp[i] = dp[l] + getCost(l+1, i-1) - slope;
		ctr[i] = ctr[l] + 1;
	}
	return {ctr[interval.size()], dp[interval.size()]};
}


long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
	vector<ii> v(n);
	for (int i = 0; i < n; ++i)
		v[i] = {min(r[i], c[i]), max(r[i], c[i])};
	sort(v.begin(), v.end(), [](const ii &x, const ii &y){
		return x.f1 < y.f1 || (x.f1 == y.f1 && x.s2 > y.s2);
	});

	interval.pb(v[0]);
	for (int i = 1; i < n; ++i)
	{
		if (interval.back().f1 <= v[i].f1 && v[i].s2 <= interval.back().s2)
			continue;
		interval.pb(v[i]);
	}

	ll L = 0, R = 1e12;
	for (int i = 0; i < interval.size(); ++i)
		L = max(L, getCost(i, i));

	k = min(k, (int)interval.size());
	while (L < R)
	{
		ll mid = (L + R) / 2;
		pl res = check(mid);

		if (res.f1 <= k) R = mid;
		else L = mid + 1;
	}
	pl res = check(L);
	return k * L + res.s2;
}

/*
int main() {
    int n, m, k;
    assert(3 == scanf("%d %d %d", &n, &m, &k));
    std::vector<int> r(n), c(n);
    for (int i = 0; i < n; i++) {
        assert(2 == scanf("%d %d", &r[i], &c[i]));
    }
    long long ans = take_photos(n, m, k, r, c);
    
    
    printf("%lld\n", ans);
    return 0;
}
*/

Compilation message

aliens.cpp: In function 'std::pair<long long int, long long int> check(int)':
aliens.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i = 2; i <= interval.size(); ++i)
      |                  ~~^~~~~~~~~~~~~~~~~~
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:74:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |  for (int i = 0; i < interval.size(); ++i)
      |                  ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 204 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Incorrect 1 ms 204 KB Wrong answer: output = 16, expected = 12
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 1
2 Incorrect 1 ms 204 KB Wrong answer: output = 1, expected = 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 204 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Incorrect 1 ms 204 KB Wrong answer: output = 16, expected = 12
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 204 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Incorrect 1 ms 204 KB Wrong answer: output = 16, expected = 12
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 204 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Incorrect 1 ms 204 KB Wrong answer: output = 16, expected = 12
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 204 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Incorrect 1 ms 204 KB Wrong answer: output = 16, expected = 12
5 Halted 0 ms 0 KB -