이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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=(a1-a)/(b-b1);
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;
}
};
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |