이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <limits.h>
using namespace std;
#define v vector
#define pii pair<int,int>
#define fi first
#define se second
int N,K;
v<pii> pos;
v<v<v<long long>>> memo;
long long diagSolve(int l, int r, int k){
long long curArea=(pos[r].se-pos[l].fi+1) * (pos[r].se-pos[l].fi+1);
//check for intersection with prev:
if(l!=0){
long long length = max(0, pos[l-1].se-pos[l].fi+1);
curArea-=length*length;
}
if(r==N-1){
return memo[l][r][k] = curArea;
}
if(k==K-1){
return memo[l][r][k] = diagSolve(l,N-1,k);
}
if(memo[l][r][k]!=-1) return memo[l][r][k];
long long takePhoto = curArea+diagSolve(r+1,r+1,k+1);
long long dont=LLONG_MAX;
if(K-k<N-l) dont = diagSolve(l,r+1,k);
return memo[l][r][k] = min(takePhoto, dont);
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
if(k==n){//sub 1
v<v<bool>> squares(m,v<bool>(m,false));
for(int i=0;i<n;i++){
int low=min(r[i],c[i]);
int high=max(r[i],c[i]);
for(int a=low;a<=high;a++){
for(int b=low;b<=high;b++){
squares[a][b]=true;
}
}
}
long long out=0;
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
out+=squares[i][j];
}
}
return out;
}
else{
K=k;
set<pii> tmp;
for(int i=0;i<n;i++){
tmp.insert({r[i],-c[i]});
}
for(pii it:tmp){
if(pos.size()==0) {
pos.push_back({it.fi,-it.se});
continue;
}
if(it.fi<=pos.back().se && -it.se<=pos.back().se) continue;
pos.push_back({it.fi,-it.se});
}
N=pos.size();
memo=v<v<v<long long>>>(N+1,v<v<long long>>(N+1,v<long long>(k+1,-1)));
return diagSolve(0,0,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... |