Submission #246439

#TimeUsernameProblemLanguageResultExecution timeMemory
246439BartolMAliens (IOI16_aliens)C++17
4 / 100
6 ms384 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define X first #define Y second #define mp make_pair typedef pair <int, int> pii; typedef double ll; typedef pair <ll, ll> pll; typedef pair <pll, int> ppi; typedef pair <ll, int> pli; const int N=1e5+5; const int INF=0x3f3f3f3f; const ll MAX=(ll)INF*INF; const int K=4005; vector <pii> v, vec; vector <ppi> hull; int ind; int cnt[N]; ll dp[N]; ll ccw(pll a, pll b, pll c) { return a.X*(b.Y-c.Y)+b.X*(c.Y-a.Y)+c.X*(a.Y-b.Y); } int cmp1(pii a, pii b) { if (a.X==b.X) return a.Y>b.Y; return a.X<b.X; } ll f(pll a, ll x) { return a.X*x+a.Y; } pli bin(ll x) { if (hull.empty()) return mp(MAX, 0); while (ind<(int)hull.size()-1 && f(hull[ind].X, x)>f(hull[ind+1].X, x)) ++ind; return mp(f(hull[ind].X, x), hull[ind].Y+1); } void dodaj(ppi pp) { while (hull.size()>1 && ccw(hull[(int)hull.size()-2].X, hull.back().X, pp.X)<=0) { hull.pop_back(); } hull.pb(pp); } void solve(ll lambda, int n) { ind=0; cnt[0]=0; hull.clear(); hull.pb(mp(mp(2*v[1].X, (ll)v[1].X*v[1].X), 0)); for (int i=1; i<=n; ++i) { ll ri=-v[i].Y-1; pli curr=bin(ri); curr.X+=ri*ri+lambda; cnt[i]=curr.Y; dp[i]=curr.X; ll pres=0; if (i!=n) pres=max(0.0, (ll)(v[i].Y-v[i+1].X+1)); if (i!=n) dodaj(mp(mp(2*v[i+1].X, curr.X-pres*pres+(ll)v[i+1].X*v[i+1].X), curr.Y)); } } long long take_photos(int n, int m, int k, vector<int> rr, vector<int> cc) { // printf("%lld\n", MAX); for (int i=0; i<n; ++i) { if (rr[i]>cc[i]) swap(rr[i], cc[i]); vec.pb(mp(rr[i], cc[i])); } sort(vec.begin(), vec.end(), cmp1); int maxi=-1; for (int i=0; i<n; ++i) { if (maxi>=vec[i].Y) continue; maxi=vec[i].Y; v.pb(vec[i]); // printf("dodajem [%d %d]\n", vec[i].X, vec[i].Y); } n=v.size(); v.insert(v.begin(), mp(-1, -1)); ll lo=0, hi=(ll)m*m, mid, br=0; while (br<50) { mid=(lo+hi)/2; solve(mid, n); if (cnt[n]>k) lo=mid+1; else hi=mid; br++; } solve(lo, n); return (long long)dp[n]-(long long)lo*cnt[n]; /*for (int i=1; i<=n; ++i) { for (int j=k; j>=1; --j) { // printf("i: %d, j: %d\n", i, j); ll ri=-v[i].Y-1; ll curr=bin(j-1, ri)+ri*ri; // printf("i: %d, j: %d, dp: %lld\n", i, j, curr); ll pres=0; if (i!=n) pres=max(0LL, (ll)(v[i].Y-v[i+1].X+1)); if (i!=n) dodaj(j, mp(2*v[i+1].X, curr-pres*pres+(ll)v[i+1].X*v[i+1].X)); if (i==n && j==k) sol=curr; // for (int l=0; l<i; ++l) { // ll ri=-v[i].Y-1; // ll curr= // ll curr=dp[l][j-1]+(ll)(v[i].Y-v[l+1].X+1)*(ll)(v[i].Y-v[l+1].X+1); // ll presj=max(0LL, (ll)(v[l].Y-v[l+1].X+1)); // // dp[i][j]=min(dp[i][j], curr-presj*presj); // } } }*/ } /* 2 6 2 1 4 4 1 5 9 2 0 0 1 1 2 2 5 5 9 9 5 7 2 0 3 4 4 4 6 4 5 4 6 */
#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...