Submission #41233

# Submission time Handle Problem Language Result Execution time Memory
41233 2018-02-14T17:46:47 Z MatheusLealV Aliens (IOI16_aliens) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define inf 2000000000000000000LL
#define N 100005
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;

ll n, m, k;

pii ini[N], v[N];

vector<pii> aux;

int r;

vector<pair<pii, int> > f;

pii F(ll x, ll id)
{
	return {f[id].f.f*x + f[id].f.s, f[id].s};
}

bool bad(pii C, pii B, pii A)
{
	return (B.s - A.s)*(A.f - C.f) < (C.s - A.s)*(A.f - B.f);
}

void addline(pair<pii, int> l)
{
	ll p = f.size();
	if(p < 2) f.push_back(l);
	else
	{
		while(p >= 2 && bad(f[p - 2].f, f[p - 1].f, l.f))
		{
			p--;
			f.pop_back();
		}
		f.push_back(l);
	}
}

pii query(ll x)
{
	ll p = f.size();

	if(r >= p) r = p - 1;

	while(r < p - 1 && F(x, r) > F(x, r + 1)) r++;

	return F(x, r);
}

bool cmp(pii esq, pii dir)
{
	if(esq.f != dir.f) return esq.f < dir.f;

	return esq.s > dir.s;
}

pii dp[N];

pii solve(ll cost)
{
	for(int i = 1; i <= n; i++)
	{
		ll dc = 0;

		if(i > 1) dc = max(0LL, (v[i - 1].s - v[i].f + 1));

		dc = dc*dc; 

		pii reta = {-2*v[i].f, dp[i - 1].f + v[i].f*v[i].f - 2*v[i].f - dc};

		addline({ reta, dp[i - 1].s });

		ll cte = v[i].s*v[i].s + 2*v[i].s + 1, X = v[i].s;

		dp[i] = query(X);

		dp[i].f += cost + cte, dp[i].s ++;
	}

	f.clear();

	return dp[n];
}

int main()
{
	cin>>n>>m>>k;

	for(int i = 1, x, y; i <= n; i++)
	{
		cin>>x>>y;

		ini[i] = {min(x, y), max(x, y)};
	}

	sort(ini + 1, ini + n + 1, cmp);

	for(int i = 1; i <= n; i++)
	{
		pii st = ini[i];

		aux.push_back(st);

		while(i <= n && (ini[i].s <= st.s)) i++;

		i --;
	}

	n = aux.size();

	for(int i = 1; i <= n; i++) v[i] = aux[i - 1];

	for(int i = 1; i <= n; i++)
	{
		dp[i] = { (v[i].s - v[1].f + 1)*(v[i].s - v[1].f + 1), 1 };
	}

	k = min(k, n);

	ll ini = 0, fim = (ll)5000000000000, mid;

	for(int cnt = 0; cnt < 50; cnt ++)
	{
		mid = (ini + fim)/2;

		pii p = solve(mid);

		if(p.s > k) ini = mid;

		else if(p.s < k)fim = mid + 1;
	}

	solve(mid);

	cout<<dp[n].f - mid*k<<"\n";
}

Compilation message

/tmp/ccQGSXkV.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccOvMJXX.o:aliens.cpp:(.text.startup+0x0): first defined here
/tmp/ccQGSXkV.o: In function `main':
grader.cpp:(.text.startup+0xdf): undefined reference to `take_photos(int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status