이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define sep ' '
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1000 + 10;
int n, m, k;
ll dp[MAXN][MAXN], f[MAXN];
inline ll pw(ll a) {
return a * a;
}
inline ll calc() {
vector<int> opts;
ll mx_f = -1;
for (int i = 0; i < m; i++) {
if (f[i] > mx_f) {
mx_f = f[i];
opts.push_back(i);
}
}
for (int e : opts) {
int len = f[e] - e + 1;
dp[e][1] = pw(len + e - opts.front());
for (int ii = 0; ii < int(opts.size()); ii++) {
int e2 = opts[ii];
if (e2 >= e) break;
int tlen = len + (e - opts[ii + 1]);
int mn_cov = opts[ii + 1];
for (int j = 1; j <= k; j++) {
dp[e][j] = min(dp[e][j], dp[e2][j - 1] + pw(tlen) - (mn_cov > f[e2] ? 0 : pw(f[e2] - mn_cov + 1)));
}
}
}
ll ans = numeric_limits<ll>::max();
for (int j = 1; j <= k; j++)
ans = min(ans, dp[opts.back()][j]);
return ans;
}
ll take_photos(int n_, int m_, int k_, vector<int> r, vector<int> c) {
fill(f, f + MAXN, -1);
memset(dp, 63, sizeof dp);
n = n_, m = m_, k = k_;
for (int i = 0; i < n; i++) {
int x = r[i], y = c[i];
if (y < x) swap(x, y); // TODO: check
f[x] = max(f[x], ll(y));
}
return calc();
}
# | 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... |