제출 #420995

#제출 시각아이디문제언어결과실행 시간메모리
420995HegdahlAliens (IOI16_aliens)C++17
0 / 100
1 ms272 KiB
#include <bits/stdc++.h> #include "aliens.h" #define ar array using namespace std; using ll = long long; int n; vector<ar<ll, 2>> p; vector<ll> ul, dr; ar<ll, 2> go(ll penalty) { //cerr << penalty << '\n'; ll real_cost = 0; ll total_used = 1; ll cur_ul = ul[0], cur_dr = dr[0]; ll cur_w = cur_dr-cur_ul+1; for (int i = 1; i < n; ++i) { ll extend_ul = min(cur_ul, ul[i]); ll extend_dr = max(cur_dr, dr[i]); ll extend_w = extend_dr - extend_ul + 1; ll extend_cost = extend_w*extend_w - cur_w*cur_w; ll new_w = dr[i]-ul[i]+1; ll new_cost = new_w*new_w + penalty; if (extend_cost < new_cost) { cur_ul = extend_ul; cur_dr = extend_dr; cur_w = extend_w; } else { //cerr << cur_w << ' '; real_cost += cur_w * cur_w; ++total_used; cur_ul = ul[i]; cur_dr = dr[i]; cur_w = new_w; } } real_cost += cur_w * cur_w; //cerr << cur_w << '\n'; //cerr << real_cost << ' ' << total_used << '\n'; //cerr << '\n'; return {real_cost, total_used}; } long long take_photos(int n_, int m, int k, vector<int> r, vector<int> c) { n = n_; p.resize(n); ul.resize(n); dr.resize(n); for (int i = 0; i < n; ++i) p[i] = {r[i], c[i]}; sort(p.begin(), p.end(), [&](auto a, auto b) { return min(a[0], a[1]) < min(b[0], b[1]); }); for (int i = 0; i < n; ++i) ul[i] = min(p[i][0], p[i][1]); for (int i = 0; i < n; ++i) dr[i] = max(p[i][0], p[i][1]); /* cerr << "ul: "; for (int i = 0; i < n; ++i) cerr << ul[i] << " \n"[i==n-1]; cerr << "dr: "; for (int i = 0; i < n; ++i) cerr << dr[i] << " \n"[i==n-1]; // */ const ll INF = 1LL<<50; ll ans = INF; ll lo = 0, hi = INF; while (lo != hi) { ll ce = lo + (hi-lo)/2; auto [cost, used] = go(ce); if (used > k) lo = ce+1; else hi = ce; } hi = INF; while (lo < hi) { ll ce1 = lo + (hi-lo)/2; ll ce2 = ce1+1; auto [cost1, used1] = go(ce2); auto [cost2, used2] = go(ce2); ans = min({ans, cost1, cost2}); if (cost1 > cost2) lo = ce1+1; else hi = ce2-1; } 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...