이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
const int MXN=4e3+5, INF=1e9;
int N,M,K;
array<int,2> arr[MXN];
int dp[MXN], amt[MXN];
bool cc1(const array<int,2> &a, const array<int,2> &b) {
if (a[0]==b[0]) {
return a[1]>b[1];
}
return a[0]<b[0];
}
bool cc2(const array<int,2> &a, const array<int,2> &b) {
return a[1]<b[1];
}
int check(int w) {
memset(dp,0x3f,sizeof(dp));
memset(amt,0,sizeof(amt));
dp[0] = 0;
for (int i=1; i<=N; i++) {
for (int p=0; p<i; p++) {
int area = (arr[i][1]-arr[p+1][0]+1)*(arr[i][1]-arr[p+1][0]+1);
int dif = 1ll*max(0ll,arr[p][1]-arr[p+1][0]+1ll)*max(0ll,arr[p][1]-arr[p+1][0]+1ll);
area -= dif;
int val = dp[p]+area+w;
if (val < dp[i]) {
dp[i] = val, amt[i] = amt[p]+1;
}
}
}
return amt[N];
}
int search(int lo, int hi) {
if (lo==hi) return lo;
if (lo+1==hi) {
if (check(hi)==K) return hi;
return lo;
}
int mid = (lo+hi)/2;
if (check(mid) <= K) {
return search(lo,mid);
}
return search(mid,hi);
}
int take_photos(int32_t n, int32_t m, int32_t k, vector<int32_t> r, vector<int32_t> c) {
N = n, M = m, K = k;
for (int i=1; i<=N; i++) {
arr[i] = {min(r[i-1],c[i-1]),max(r[i-1],c[i-1])};
}
arr[0] = {-INF,-INF};
sort(arr,arr+N+1,cc1);
int pv = 0,sub = 0;
for (int i=1; i<=N; i++) {
if (arr[pv][1] >= arr[i][1]) {
sub++; arr[i] = {INF,INF};
} else pv = i;
}
sort(arr,arr+1+N,cc2);
N -= sub; K = min(K,N);
int w = search(-1e12,1e12);
check(w);
while (amt[N] > K) {
w++; check(w);
}
return dp[N]-w*(K);
}
/*
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int32_t a,b,c; cin>>a>>b>>c;
vector<int32_t> x(a),y(a);
for (int i=0; i<a; i++) {
cin>>x[i]>>y[i];
}
cout<<take_photos(a,b,c,x,y);
return 0;
}
*/
# | 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... |