Submission #130508

#TimeUsernameProblemLanguageResultExecution timeMemory
130508fefeAliens (IOI16_aliens)C++17
0 / 100
3 ms376 KiB
#include<bits/stdc++.h> #include "aliens.h" #define MAX_N 100005 #define fi first #define se second #define sq(x) ((x)*(x)) using namespace std; typedef long long LL; typedef pair<LL,LL> pil; struct node{ LL s,e; }V[MAX_N]; LL s,e; LL dp[MAX_N]; pil L[MAX_N]; bool is_ok(pil a,pil b,pil c){ return (b.se-a.se)*(b.fi-c.fi)<(a.fi-b.fi)*(c.se-b.se); } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { LL i; for(i=1;i<=n;i++){ V[i].s=min(r[i-1],c[i-1]); V[i].e=max(r[i-1],c[i-1]); } sort(V+1,V+n+1,[&](const node x,const node y){return (x.s==y.s)?(x.e>y.e):(x.s<y.s);}); m=0; LL x=-1; for(i=1;i<=n;i++){ if(x<V[i].e) V[++m]=V[i]; x=max(x,V[i].e); } n=m; sort(V+1,V+n+1,[&](const node x,const node y){return x.e<y.e;}); s=e=0; L[e++]={-2*V[1].s,sq(V[1].s)-2*V[1].s}; for(i=1;i<=n;i++){ while(e-s>1 && L[s].fi*V[i].e+L[s].se>=L[s+1].fi*V[i].e+L[s+1].se) s++; dp[i]=L[s].fi*V[i].e+L[s].se+sq(V[i].e+1); pil p={-2*V[i+1].s,sq(V[i+1].s)-2*V[i+1].s+dp[i]}; if(V[i].e-V[i+1].s+1>0) p.se+=sq(V[i].e-V[i+1].s+1); while(e-s>1 && !is_ok(L[e-2],L[e-1],p)) e--; L[e++]=p; } return dp[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...