Submission #637679

#TimeUsernameProblemLanguageResultExecution timeMemory
637679ggohAliens (IOI16_aliens)C++14
41 / 100
228 ms159984 KiB
#include "aliens.h" #include<bits/stdc++.h> using namespace std; #define sz(v) ((int)(v).size()) typedef long long lint; typedef pair<int,int> pii; vector<pii>Vtmp,V; lint sq(int L) { return 1ll*L*L; } int a[500004],b[500004]; struct Line{ lint a,b; }; vector<Line>CHT[4004]; int piv[4004]; bool check1(Line A,Line B,Line C) { if((__int128)(B.b-A.b)*(B.a-C.a) > (__int128)(C.b-B.b)*(A.a-B.a))return 1; else return 0; } bool check2(Line A,Line B,lint x) { if((__int128)(B.b-A.b) < (__int128)x*(A.a-B.a)) return 1; else return 0; } void insert_line(int num,Line L) { while(sz(CHT[num])>2 && check1(CHT[num][sz(CHT[num])-2],CHT[num][sz(CHT[num])-1],L))CHT[num].pop_back(); CHT[num].push_back(L); } lint get_min(int num,lint x) { if(CHT[num].empty())return 1e18; if(piv[num]>=sz(CHT[num]))piv[num]=sz(CHT[num])-1; while(piv[num]+1<sz(CHT[num]) && check2(CHT[num][piv[num]],CHT[num][piv[num]+1],x))piv[num]++; return CHT[num][piv[num]].a * x + CHT[num][piv[num]].b; } lint take_photos(int n, int m, int K, std::vector<int> r, std::vector<int> c) { lint D[n+1][K+1]; for(int i=0;i<n;i++) { if(r[i]<c[i])swap(r[i],c[i]); Vtmp.push_back({r[i],-c[i]}); } sort(Vtmp.begin(),Vtmp.end()); int mini=1e9; for(int i=sz(Vtmp)-1;i>=0;i--) { if(mini>-Vtmp[i].second)V.push_back({Vtmp[i].first,-Vtmp[i].second}); mini=min(mini,-Vtmp[i].second); } sort(V.begin(),V.end()); n=sz(V); for(int i=1;i<=n;i++) { a[i]=V[i-1].second; b[i]=V[i-1].first+1; } insert_line(0,{-2*a[1],sq(a[1])}); K=min(K,n); for(int i=0;i<=K;i++)piv[i]=0; for(int i=1;i<=n;i++) { for(int k=min(K,i);k>=1;k--) { D[i][k]=get_min(k-1,b[i])+sq(b[i]); insert_line(k,{-2*a[i+1],D[i][k]+sq(a[i+1])-sq(b[i]-min(b[i],a[i+1]))}); } } lint ans=1e18; for(int k=1;k<=K;k++)ans=min(ans,D[n][k]); 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...