이 제출은 이전 버전의 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
#define ll long long
int N,K;
v<pii> pos;
v<v<long long>> memo;
long long diagSolve(int cur, int k){//cover first cur with k photos
if(memo[cur][k]!=-1) return memo[cur][k];
if(cur==0) return memo[cur][k] = 0;
if(k==0) return LLONG_MAX/2;
long long ret=LLONG_MAX/2;
for(int i=0;i<cur;i++){
long long curArea=(pos[cur-1].se-pos[i].fi+1) * (pos[cur-1].se-pos[i].fi+1);
//check for intersection with prev:
if(i!=0){
long long length = max(0, pos[i-1].se-pos[i].fi+1);
curArea-=length*length;
}
long long take = diagSolve(i,k-1);
if(take+curArea<ret) ret=take+curArea;
}
return memo[cur][k] = ret;
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
K=k;
set<pii> tmp;
for(int i=0;i<n;i++){
tmp.insert({min(r[i],c[i]),-max(c[i],r[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<ll>>(N+1,v<long long>(k+1,-1));
return diagSolve(N,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... |