이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define fopen freopen("input.txt", "r", stdin)
#define pb push_back
#define prec(a) cout<<fixed;cout.precision(a);
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tiii;
const ll INF = 9e18;
const int inf = 2e9;
template<class T>
void pr(T t) {cout << t << " ";}
template<class T, class ...Args>
void pr(T a, Args ...args) {cout << a << " ";pr(args...);}
template<class ...Args>
void prl(Args ...args) {pr(args...);cout << endl;}
ll dp[510][510];
ll take_photos(int n, int m, int k, vector<int>x, vector<int>y){
vector<pii> tmp,p;
for(int i=0;i<n;i++){
if(x[i]>y[i]) swap(x[i], y[i]);
tmp.pb({x[i],y[i]});
}
sort(tmp.begin(), tmp.end(), [](pii a, pii b){if(a.se==b.se) return a.fi>b.fi;return a.se<b.se;});
for(auto i:tmp){
while(!p.empty()&&p[p.size()-1].fi>=i.fi) p.pop_back();
p.pb(i);
}
for(int i=0;i<(int)p.size();i++){
dp[i][0]=INF;
for(int j=1;j<=k;j++){
dp[i][j]=dp[i][j-1];
for(int ii=0;ii<=i;ii++){
if(ii==0) dp[i][j]=min(dp[i][j],(ll)(p[i].se-p[ii].fi+1)*(p[i].se-p[ii].fi+1));
else dp[i][j]=min(dp[i][j],dp[ii-1][j-1]+(p[i].se-p[ii].fi+1)*(p[i].se-p[ii].fi+1)-(ll)(p[ii-1].se-p[ii].fi+1)*(p[ii-1].se-p[ii].fi+1)*(p[ii].fi<=p[ii-1].se));
}
}
}
return dp[p.size()-1][k];
}
# | 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... |