제출 #41234

#제출 시각아이디문제언어결과실행 시간메모리
41234MatheusLealVAliens (IOI16_aliens)C++14
100 / 100
191 ms69728 KiB
#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]; } ll take_photos(int N_, int M_, int K_, vector<int> r, vector<int> c) { n = N_, m = M_, k = K_; for(int i = 0; i < n; i++) { int x = r[i], y = c[i]; ini[i + 1] = {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); return dp[n].f - mid*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...