이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "aliens.h"
using namespace std;
const int MAX_K = 1005;
const int MAX_N = 1005;
const long long INF = 1e18 + 7;
int N, M, K;
int id[MAX_N];
long long dp[MAX_K][MAX_N];
int qs[MAX_N][MAX_N];
bool dead[MAX_N];
long long take_photos(int n, int m, int k, vector <int> r, vector <int> c) {
N = n, M = m, K = k;
if (K == N) {
long long ans = 0;
for (int i = 0; i < N; i++) {
int x = min(r[i], c[i]) + 1, y = max(r[i], c[i]) + 1;
qs[x][x]++;
qs[x][y + 1]--;
qs[y + 1][x]--;
qs[y + 1][y + 1]++;
}
for (int i = 1; i <= M; i++) {
for (int j = 1; j <= M; j++) {
qs[i][j] += qs[i - 1][j] + qs[i][j - 1] - qs[i - 1][j - 1];
if (qs[i][j] > 0) ans++;
}
}
return ans;
}
for (int i = 0; i < N; i++) id[i] = i;
sort(id, id + N, [&](const int &a, const int &b) {
return r[a] < r[b];
});
for (int i = 1; i <= N; i++) dp[0][i] = INF;
for (int k = 1; k <= K; k++) {
for (int i = 1; i <= N; i++) {
dp[k][i] = INF;
for (int j = i; j >= 1; j--) {
long long cost = (r[id[i - 1]] - r[id[j - 1]] + 1) * (r[id[i - 1]] - r[id[j - 1]] + 1);
dp[k][i] = min(dp[k][i], cost + dp[k - 1][j - 1]);
}
}
}
long long ans = INF;
for (int k = 1; k <= K; k++) ans = min(ans, dp[k][N]);
return ans;
}
# | 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... |