제출 #519140

#제출 시각아이디문제언어결과실행 시간메모리
519140AdamGSAliens (IOI16_aliens)C++17
4 / 100
1 ms308 KiB
#include "aliens.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e5+7;
pair<ll,ll>T[LIM];
ll dp[LIM], lst[LIM], n, m, k;
ll licz(ll a, ll b) {
	ll ans=b-a+1;
	if(ans<=0) return 0;
	return ans*ans;
}
int solve(ll c) {
	rep(i, n) {
		lst[i+1]=lst[i];
		dp[i+1]=dp[lst[i+1]-1]+licz(T[lst[i+1]].st, T[i+1].nd)-licz(T[i+1].st, T[lst[i+1]-1].nd);
		while(lst[i+1]<i+1) {
			ll nowe=dp[lst[i+1]];
			nowe+=licz(T[lst[i+1]+1].st, T[i+1].nd)-licz(T[i+1].st, T[lst[i+1]].nd);
			if(nowe<dp[i+1]) {
				dp[i+1]=nowe;
				++lst[i+1];
			} else break;
		}
		dp[i+1]+=c;
	}
	int ans=0, akt=n;
	while(akt) {
		++ans;
		akt=lst[akt]-1;
	}
	return ans;
}
ll take_photos(int N, int M, int K, vector<int>r, vector<int>c) {
	pair<ll,ll>P[N];
	rep(i, N) P[i]={min(r[i], c[i]), -max(r[i], c[i])};
	sort(P, P+N);
	ll ma=-1;
	rep(i, N) {
		if(-P[i].nd>ma) {
			ma=-P[i].nd;
			++n;
			T[n]={P[i].st, -P[i].nd};
		}
	}
	m=M; k=K;
	T[0]={-1, -1};
	lst[0]=1;
	ll po=0, ko=10000000000000;
	while(po<ko) {
		ll sr=(po+ko)/2;
		if(solve(sr)>k) po=sr+1; else ko=sr;
	}
	ll x=solve(po);
	return dp[n]-po*x;
}
#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...