제출 #389082

#제출 시각아이디문제언어결과실행 시간메모리
389082alishahali1382Aliens (IOI16_aliens)C++14
41 / 100
1847 ms751364 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define debug(x) {cerr<<#x<<"="<<x<<"\n";} #define debug2(x, y) {cerr<<#x<<", "<<#y<<" = "<<x<<", "<<y<<"\n";} #define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";} #define pb push_back #define all(x) x.begin(), x.end() const int inf=1000001000; const ll INF=10000000010000000; const int MAXN=4010, K=4010; int n, m, k; pii A[MAXN]; ll dp[4010][4010]; ll Inter(pll a, pll b){ if (a.first==b.first) return (a.second<=b.second?-INF:INF); return (a.second-b.second)/(b.first-a.first) + ((a.second-b.second)%(b.first-a.first)>0); } struct CHT{ pair<ll, pll> A[MAXN]; int sz; inline void Add(pll x){ while (sz && Inter(A[sz-1].second, x)<=A[sz-1].first) sz--; if (!sz) A[sz++]={-INF, x}; else A[sz]={Inter(A[sz-1].second, x), x}, sz++; } inline ll Get(ll x){ pll p=(upper_bound(A, A+sz, make_pair(x, pll(INF, INF)))-1)->second; return p.first*x+p.second; } } cht[K]; inline ll _sq(ll x){ return x*x;} ll take_photos(int _n, int _m, int _k, vector<int> r, vector<int> c) { k=_k; m=_m; vector<pii> vec; for (int i=0; i<_n; i++) vec.pb({min(r[i], c[i]), max(r[i], c[i])}); sort(all(vec), [](pii i, pii j){ if (i.second!=j.second) return i.second<j.second; return i.first>j.first; }); for (pii p:vec){ while (n && p.first<=A[n].first) n--; A[++n]=p; } // for (int i=1; i<=n; i++) debugp(A[i]) k=min(k, n); memset(dp, 63, sizeof(dp)); for (int i=0; i<=k; i++) dp[0][i]=0; for (int i=1; i<=n; i++){ for (int t=0; t<k; t++){ ll val=_sq(A[i].first)+dp[i-1][t]; if (i!=1 && A[i].first<=A[i-1].second) val-=_sq(A[i-1].second-A[i].first+1); cht[t].Add({2*A[i].first, -val}); } for (int t=1; t<=k; t++){ dp[i][t]=_sq(A[i].second+1)-cht[t-1].Get(A[i].second+1); } } return dp[n][k]; }
#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...