이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 5e2 + 7;
const int K = N;
const long long inf = 1e18;
bool cmp(pair<long long, long long> lvalue, pair<long long, long long> rvalue){
if(lvalue.first != rvalue.first){
return lvalue.first < rvalue.first;
}
return lvalue.second > rvalue.second;
}
pair<long long, long long> p[N];
pair<long long, bool> dp[N][K];
long long solve(int pos, int left){
if(left < 0){
return inf;
}
if(pos < 0){
return 0;
}
if(left == 0){
return inf;
}
if(dp[pos][left].second){
return dp[pos][left].first;
}
dp[pos][left].second = true;
dp[pos][left].first = inf;
for(int i = pos; i >= 0; i--){
long long curr = solve(i - 1, left - 1);
curr += (p[pos].second - p[i].first + 1ll) * (p[pos].second - p[i].first + 1ll);
dp[pos][left].first = min(dp[pos][left].first, curr);
}
if(p[pos].second >= p[pos + 1].first){
dp[pos][left].first -= (p[pos].second - p[pos + 1].first + 1ll) * (p[pos].second - p[pos + 1].first + 1ll);
}
return dp[pos][left].first;
}
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
for(int i = 0; i < n; i++){
if(r[i] > c[i]){
swap(r[i], c[i]);
}
p[i].first = r[i];
p[i].second = c[i];
}
sort(p, p + n, cmp);
int mx = -1, j = 0;
for(int i = 0; i < n; i++){
if(p[i].second <= mx){
continue;
}
//cout << p[i].first << " p[i] " << p[i].second << endl;
mx = p[i].second;
p[j] = p[i];
j++;
}
n = j;
p[n].first = inf;
return solve(n - 1, k);
}
/*
5 7 2
0 3
4 4
4 6
4 5
4 6
*/
| # | 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... |