제출 #732464

#제출 시각아이디문제언어결과실행 시간메모리
732464senthetaAliens (IOI16_aliens)C++17
25 / 100
158 ms2276 KiB
#include "aliens.h"
// author : sentheta aka vanwij
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<random>
#include<chrono>
#include<cmath>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;

#define Int long long
#define V vector
#define pii pair<int,int>
#define ff first
#define ss second

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))

#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define dbg(x) if(1) cout << "?" << #x << " : " << (x) << endl << flush;
#define cerr if(0) cerr

const int N = 505;
const int K = 505;
const int M = 1e6+5;

int n, m, k;

Int dp[N][K];
inline Int sqr(Int x){return x*x;}
const Int INF = 1e18;



Int take_photos(int _n,int _m,int _k,V<int> l,V<int> r){
	n = _n; m = _m; k = _k;

	// remove subsegments
	V<int> ord;
	rep(i,0,n){
		if(l[i] > r[i]) swap(l[i], r[i]);
		ord.push_back(i);
	}
	sort(all(ord),[&](int i,int j){
		if(l[i]==l[j]) return r[i] < r[j];
		return l[i] > l[j];
	});
	V<int> stak;
	for(int i : ord){
		while(!stak.empty() && r[stak.back()]<=r[i]) stak.pop_back();
		stak.push_back(i);
	}
	reverse(all(stak));
	ord.swap(stak);
	// result is ordered from l

	{
		V<int> vl, vr;
		for(int i : ord){
			cerr << l[i] _ r[i] << nl;
			vl.push_back(l[i]);
			vr.push_back(r[i]);
		}
		l.swap(vl);
		r.swap(vr);
	}
	n = ord.size();

	// dp[0][p]
	rep(p,1,k+1) dp[0][p] = sqr(r[0]-l[0]+1);
	// dp[i][0]
	rep(i,0,n) dp[i][0] = INF;

	rep(i,1,n) rep(p,1,k+1){
		// merge all
		dp[i][p] = sqr(r[i]-l[0]+1);

		// merge j until i
		for(int j=1; j<=i; j++){
			dp[i][p] = min({
				dp[i][p],
				dp[j-1][p-1] + sqr(r[i]-l[j]+1) - (l[j]<=r[j-1] ? sqr(r[j-1]-l[j]+1):0)
			});
		}
	}

	Int ans = dp[n-1][k];
	return ans;
}
#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...