Submission #97219

#TimeUsernameProblemLanguageResultExecution timeMemory
97219onjo0127Aliens (IOI16_aliens)C++11
100 / 100
169 ms10112 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; using pli = pair<ll, int>; #define fi first #define se second int c[100009]; ll D[100009]; inline ll p(ll x) { return x*x; } struct line { ll a, b; int idx; }; line stk[100009]; int t, j; inline bool del(line P, line Q, line R) { return (R.a - P.a) * (Q.b - R.b) < (R.a - Q.a) * (P.b - R.b); } void add(line P) { while(1<=t && del(stk[t-1], stk[t], P)) --t, j = min(j, t); stk[++t] = P; } pli DP(vector<pll>& A, ll lambda) { int N = (int)A.size() - 1; for(int i=1; i<N; i++) D[i] = 1LL * 1e18, c[i] = 0; t = -1; add((line){-2LL * A[1].fi, p(A[1].fi) - 2*A[1].fi, 0}); j = 0; for(int i=1; i<N; i++) { while(j<t && A[i].se * stk[j].a + stk[j].b > A[i].se * stk[j+1].a + stk[j+1].b) ++j; ll nw = A[i].se * stk[j].a + stk[j].b + p(A[i].se) + 2*A[i].se + 1 + lambda; if(D[i] > nw) D[i] = nw, c[i] = c[stk[j].idx] + 1; add({-2LL * A[i+1].fi, D[i] + p(A[i+1].fi) - 2*A[i+1].fi - p(max(0LL, A[i].se - A[i+1].fi + 1)), i}); } return {D[N-1], c[N-1]}; } long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) { vector<pll> A, B; for(int i=0; i<n; i++) { if(r[i] > c[i]) swap(r[i], c[i]); A.push_back({r[i], c[i]}); } sort(A.begin(), A.end(), [&](pll P, pll Q) { if(P.se == Q.se) return P.fi > Q.fi; return P.se < Q.se; }); B.push_back({-1, -1}); for(int i=0; i<n; i++) { while(B.size() && B.back().fi >= A[i].fi) B.pop_back(); B.push_back(A[i]); } B.push_back({0, 0}); long long L = 0, R = 1LL*1e12, f = 0; while(L <= R) { long long m = L+R >> 1, v; int cnt; tie(v, cnt) = DP(B, m); if(cnt > k) L = m+1; else R = m-1, f = v - m * k; } return f; }

Compilation message (stderr)

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:62:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         long long m = L+R >> 1, v; int cnt;
                       ~^~
#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...