이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;
template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;
#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;
#define int ll
const int N = 1e5 + 10, M = 2e3 + 10, INF = 0x3f3f3f3f3f3f3f3f;
int suff[N];
int eliminate(int *a, int n, pair<int, int> *b) {
suff[n] = +INF;
for (int i = n; i--; ) {
suff[i] = min(suff[i + 1], a[i]);
}
int mn = +INF, m = 0;
for (int i = 0; i < n; ++i) {
if (mn <= a[i] && suff[i + 1] <= a[i]) {
continue;
}
b[m++] = {a[i], i};
}
return m;
}
int a[N], b[N];
pair<int, int> c[M], d[M];
int dp[M][M];
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
n = eliminate(a, n, c);
m = eliminate(b, m, d);
fill(dp[0], dp[M], +INF);
dp[0][0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + d[j].x * (c[i + 1].y - c[i].y));
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + c[i].x * (d[j + 1].y - d[j].y));
}
}
cout << dp[n - 1][m - 1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |