Submission #637716

#TimeUsernameProblemLanguageResultExecution timeMemory
637716ggohAliens (IOI16_aliens)C++14
0 / 100
0 ms212 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; }; Line st[500004]; int sz; int N; lint D[500004],E[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; } 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; K=min(K,n); for(int i=1;i<=n;i++)D[i]=sq(b[i]-a[1]); for(int k=2;k<=K;k++) { for(int i=1;i<=n;i++)E[i]=D[i]; int piv=1; sz=0; for(int i=k;i<=n;i++) { Line ne={-2*a[i],E[k]+sq(a[i])-sq(b[i-1]-min(b[i-1],a[i]))}; while(sz>=2 && check1(st[sz-1],st[sz],ne))sz--; if(piv>sz)piv=sz; st[++sz]=ne; while(piv<sz && check2(st[piv-1],st[piv],b[i]))piv++; Line j=st[piv]; D[i]=j.a*b[i]+j.b+sq(b[i]); } } return D[n]; }
#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...