이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
long long solve1(int n, int m, int k, vector<int> r, vector<int> c){
vector<vector<bool>> grid(m, vector<bool>(m));
for (int i = 0; i < n; ++i){
for (int j = min(r[i], c[i]); j <= max(r[i], c[i]); ++j){
for (int l = min(r[i], c[i]); l <= max(r[i], c[i]); ++l) grid[j][l] = true;
}
}
int ans = 0;
for (int i = 0; i < m; ++i){
for (int j = 0; j < m; ++j){
if (grid[i][j]) ans++;
}
}
return ans;
}
long long solve2(int n, int m, int k, vector<int> r, vector<int> c){
sort(r.begin(), r.end());
vector< vector<int> > dp(n+1, vector<int>(k+1, m * m));
dp[0][0] = 0;
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= min(i, k); ++j){
for (int l = 0; l < i; ++l){
dp[i][j] = min(dp[i][j], dp[l][j-1] + (r[i-1] - r[l] + 1) * (r[i-1] - r[l] + 1));
}
}
}
int ans = m * m;
for (int i = 1; i <= k; ++i) ans = min(ans, dp[n][i]);
return ans;
}
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
bool flag = true;
for (int i = 0; i < n; ++i) {
if (r[i] != c[i]) flag = false;
}
if (!flag) return solve1(n, m, k, r, c);
else return solve2(n, m, k, r, c);
}
# | 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... |