Submission #637712

#TimeUsernameProblemLanguageResultExecution timeMemory
637712ggohAliens (IOI16_aliens)C++14
41 / 100
413 ms106348 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[500004]; int N; lint D[500004]; bool cmp(pii A,pii B){ return A.second!=B.second?A.second<B.second:A.first>B.first; } 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((int)CHT[num].size()>2 && check1(CHT[num][(int)CHT[num].size()-2],CHT[num][(int)CHT[num].size()-1],L)){ CHT[num].pop_back(); } CHT[num].push_back(L); piv[num]=min(piv[num],(int)CHT[num].size()-1); } lint gets(int num,lint x) { int q=sz(CHT[num])-1,h; while(q!=0 && !check2(CHT[num][q-1],CHT[num][q],x))q--; return CHT[num][q].a * x + CHT[num][q].b; } lint take_photos(int n, int m, int K, std::vector<int> r, std::vector<int> c) { 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(),cmp); int N=0; for(auto &z:Vtmp) { while(N && a[N]>=z.first)N--; a[N+1]=z.first; b[N+1]=z.second+1; N++; } n=N; 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[k]=gets(k-1,b[i])+sq(b[i]); if(i!=n)insert_line(k,{-2*a[i+1],D[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[k]); return ans; }

Compilation message (stderr)

aliens.cpp: In function 'lint gets(int, lint)':
aliens.cpp:45:24: warning: unused variable 'h' [-Wunused-variable]
   45 |   int q=sz(CHT[num])-1,h;
      |                        ^
#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...