# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
994241 | vjudge1 | Sightseeing in Kyoto (JOI22_kyoto) | C++17 | 6 ms | 8284 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
struct s {
ll pos, value;
bool operator <(s const& rhs) const {
return pos < rhs.pos;
}
};
ll solve(vector<s> const& a, vector<s> const& b) {
vector dp(a.size(), vector<ll>(b.size(), LLONG_MAX / 3));
dp[0][0] = 0;
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < b.size(); j++) {
if (i < a.size() - 1)
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + b[j].value * (a[i + 1].pos - a[i].pos));
if (j < b.size() - 1)
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + a[i].value * (b[j + 1].pos - b[j].pos));
}
}
return dp.back().back();
}
vector<s> compress(vector<s> const& a) {
vector<s> ret;
ll left_min = LLONG_MAX / 3;
ll right_min = LLONG_MAX / 3;
ll l = 0;
ll r = a.size() - 1;
while (l <= r) {
if (a[l].value > a[r].value) {
if (a[l].value < left_min) {
ret.push_back(a[l]);
left_min = a[l].value;
}
l++;
}
else {
if (a[r].value < right_min || r == 0) {
ret.push_back(a[r]);
right_min = a[r].value;
}
r--;
}
}
sort(ret.begin(), ret.end());
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll h, w;
cin >> h >> w;
vector<s> a(h);
for (int i = 0; i < h; i++) {
a[i].pos = i;
cin >> a[i].value;
}
vector<s> b(w);
for (int i = 0; i < w; i++) {
b[i].pos = i;
cin >> b[i].value;
}
a = compress(a);
b = compress(b);
cout << solve(a, b) << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |