Submission #505096

#TimeUsernameProblemLanguageResultExecution timeMemory
505096HappyPacManAliens (IOI16_aliens)C++14
4 / 100
3 ms1484 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e5 + 6; const ll INF = 1e12; ll dp[MAXN]; int opt[MAXN]; vector<pair<ll,ll> > inter; struct Line{ int id; ll m,c; ll f(ll x){ return m*x+c; } }; vector<Line> cht; bool check(Line f1,Line f2,Line f3){ return (f1.c-f3.c)*(f1.m-f2.m) > (f1.c-f2.c)*(f1.m-f3.m); } void ins(Line fn){ while(cht.size() > 1 && check(cht[cht.size()-2],cht.back(),fn)){ cht.pop_back(); } cht.push_back(fn); } Line query(ll x){ int l=0,r=cht.size()-1; while(l < r){ int m = (l+r)/2; if(cht[m].f(x) <= cht[m+1].f(x)) r = m; else l = m+1; } return cht[l]; } int run(ll cost){ memset(dp,1,sizeof(dp)); memset(opt,1,sizeof(opt)); dp[0] = opt[0] = 0; ins({0,-2*inter[0].first,inter[0].first*inter[0].first}); for(int i=0;i<inter.size();i++){ Line q = query(inter[i].second); ll nx = cost+inter[i].second*inter[i].second+q.f(inter[i].second); if(nx < dp[i+1]){ dp[i+1] = nx; opt[i+1] = q.id; } if(i+1 < inter.size()){ if(inter[i+1].first <= inter[i].second) ins({i+1,-2*inter[i+1].first,dp[i+1]-inter[i].second*(inter[i].second-2*inter[i+1].first)}); else ins({i+1,-2*inter[i+1].first,dp[i+1]+inter[i+1].first*inter[i+1].first}); } } cht.clear(); int cnt=0,idx=inter.size(); while(idx > 0){ idx = opt[idx]; cnt++; } return cnt; } ll take_photos(int n,int m,int k,vector<int> r,vector<int> c){ for(int i=0;i<n;i++) inter.emplace_back(1ll*min(r[i],c[i]),1ll*max(r[i],c[i])+1); sort(inter.begin(),inter.end()); vector<pair<ll,ll> > temp; for(int i=0;i<n;i++){ while(temp.size() > 0 && temp.back().first == inter[i].first && temp.back().second <= inter[i].second) temp.pop_back(); if(temp.empty() || temp.back().second < inter[i].second) temp.push_back(inter[i]); } swap(temp,inter); k = min(k,(int)inter.size()); ll L=0,R=INF; while(L < R){ ll M = (L+R+1)/2; if(run(M) < k) R = M-1; else L = M; } run(L); return dp[inter.size()]-L*k; }

Compilation message (stderr)

aliens.cpp: In function 'int run(ll)':
aliens.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=0;i<inter.size();i++){
      |                 ~^~~~~~~~~~~~~
aliens.cpp:50:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if(i+1 < inter.size()){
      |            ~~~~^~~~~~~~~~~~~~
#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...