#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define arr array
#define vec vector
#define pii pair<int, int>
#define fir first
#define sec second
const int N = 4e3 + 5, K = 4e3 + 5, INF = 1e18;
int n, k;
arr<int, N> ps, bck;
// Answer is min of dp[n][1], dp[n][2] ...
arr<arr<int, K>, N> dp;
int sq(int x) { return x * x; }
void dp_cmp() {
for (int i = 1; i <= n; i++) {
int ft = INF;
for (int j = i + 1; j <= n; j++) ft = min(ft, bck[j]);
int mn = INF;
for (int j = i; j >= 1; j--) mn = min(mn, bck[j]);
dp[i][1] = (mn <= ft) ? sq(ps[i] - mn + 1) : INF;
}
for (int c = 2; c <= k; c++) {
for (int i = 1; i <= n; i++) {
dp[i][c] = INF;
int ft = INF;
for (int j = i + 1; j <= n; j++) ft = min(ft, bck[j]);
int mn = bck[i];
for (int j = i - 1; j >= 1; j--) {
int intr = (ps[j] < mn) ? 0 : sq(ps[j] - mn + 1);
int trns = dp[j][c - 1] - intr + sq(ps[i] - mn + 1);
if (mn <= ft)
dp[i][c] = min(dp[i][c], trns);
mn = min(mn, bck[j]);
}
}
}
// for (int i = 1; i <= n; i++)
// for (int c = 1; c <= k; c++)
// cout << i << " " << c << ": " << dp[i][c] << endl;
}
map<int, int> bck_mp;
int take_photos(signed _sz, signed _m, signed _k, vec<signed> _rw, vec<signed> _cl) {
k = _k;
for (int i = 0; i < _sz; i++) {
int x = max(_rw[i] + 1, _cl[i] + 1), y = min(_rw[i] + 1, _cl[i] + 1);
if (!bck_mp.count(x)) bck_mp[x] = y;
else bck_mp[x] = min(bck_mp[x], y);
}
for (pii x : bck_mp) n++, ps[n] = x.fir, bck[n] = x.sec;
dp_cmp();
int ans = *min_element(dp[n].begin() + 1, dp[n].begin() + k + 1);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
aliens_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |