Submission #618130

#TimeUsernameProblemLanguageResultExecution timeMemory
618130rrrr10000Aliens (IOI16_aliens)C++14
60 / 100
1254 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<bool> vb; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++) #define all(a) a.begin(),a.end() #define lb(v,k) (lower_bound(all(v),k)-v.begin()) #define fi first #define se second #define pb emplace_back template<class T> void out(T a){cout<<a<<endl;} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;} template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} const ll inf=1001001001001001001; long long take_photos1(int n, int m, int K, std::vector<int> r, std::vector<int> c) { vp srt(n); rep(i,n)srt[i]=P(max(r[i],c[i]),min(r[i],c[i])); sort(all(srt)); vp v;v.pb(-1,-1); for(auto x:srt){ while(v.size()&&v.back().fi>=x.se)v.pop_back(); if(v.size()==0||v.back().se<x.fi)v.pb(x.se,x.fi); } n=v.size(); vvi dp(n,vi(K+1,inf)); dp[0][0]=0; rep(i,n)rep(j,K)if(dp[i][j]!=inf){ chmin(dp[i][j+1],dp[i][j]); REP(t,i+1,n)chmin(dp[t][j+1],dp[i][j]+(v[t].se-v[i+1].fi+1)*(v[t].se-v[i+1].fi+1)-max(0ll,v[i].se-v[i+1].fi+1)*max(0ll,v[i].se-v[i+1].fi+1)); } return dp[n-1][K]; } struct CHT{ deque<P> deq; void insert(ll a,ll b){ while(deq.size()>1){ long double a1,b1,a2,b2;tie(a1,b1)=deq[deq.size()-2];tie(a2,b2)=deq.back(); long double x=(b1-b)/(a-a1); if(a2*x+b2<a*x+b)break; deq.pop_back(); } deq.pb(a,b); } ll sol(ll x){ if(!deq.size())return inf; while(deq.size()>1){ if(deq[0].fi*x+deq[0].se<deq[1].fi*x+deq[1].se)break; deq.pop_front(); } return deq[0].fi*x+deq[0].se; } /* vp al; void insert(ll a,ll b){ al.pb(a,b); } ll sol(ll x){ ll res=inf; for(auto l:al)chmin(res,l.fi*x+l.se); return res; } */ }; long long take_photos(int n, int m, int K, std::vector<int> r, std::vector<int> c) { vp srt(n); rep(i,n)srt[i]=P(max(r[i],c[i]),min(r[i],c[i])); sort(all(srt)); vp v;v.pb(-1,-1); for(auto x:srt){ while(v.size()&&v.back().fi>=x.se)v.pop_back(); if(v.size()==0||v.back().se<x.fi)v.pb(x.se,x.fi); } n=v.size();chmin(K,n-1); vvi dp(K+1,vi(n,inf)); dp[0][0]=0; rep(k,K){ CHT cht; rep(i,n){ dp[k+1][i]=cht.sol(v[i].se)+v[i].se*v[i].se; if(i<n-1)cht.insert(2*(-v[i+1].fi+1),dp[k][i]+(-v[i+1].fi+1)*(-v[i+1].fi+1)-max(0ll,v[i].se-v[i+1].fi+1)*max(0ll,v[i].se-v[i+1].fi+1)); } } return dp[K][n-1]; }
#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...