이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tpl;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
const int mn = 1e5 + 5;
ll a[mn], b[mn], ans[mn];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
vector<tpl> checkpoints;
checkpoints.emplace_back(0, 1, 1);
fill(ans + 1, ans + 1 + n, LLONG_MAX);
ll sum = 0;
for (int i = 2; i <= n; i++) {
ll optCol = 0, optVal = LLONG_MAX;
for (int j = 0; j < checkpoints.size(); j++) {
ll val, row, curCol; tie(val, row, curCol) = checkpoints[j];
ll nxtCol = (j + 1 < checkpoints.size() ? get<2>(checkpoints[j + 1]) : m + 1);
for (int col = curCol; col < nxtCol; col++) {
ll curVal = val + a[row] * (col - curCol) + b[col] * (i - row);
if (curVal + a[i] * (m - col) < ans[i])
ans[i] = curVal + a[i] * (m - col), optCol = col, optVal = curVal;
// cout << curVal + a[i] * (m - col) << " ";
}
}
while (checkpoints.size() && get<2>(checkpoints.back()) >= optCol) checkpoints.pop_back();
checkpoints.emplace_back(optVal, i, optCol);
sum += checkpoints.size();
// cout << "row " << i << ", check-points: ";
// for (auto [a, b, c] : checkpoints) cout << a << " ";
// cout << "\n";
}
if (sum > 1000 * 10) {
while (true);
}
cout << ans[n];
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
kyoto.cpp: In function 'int main()':
kyoto.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int j = 0; j < checkpoints.size(); j++) {
| ~~^~~~~~~~~~~~~~~~~~~~
kyoto.cpp:34:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | ll nxtCol = (j + 1 < checkpoints.size() ? get<2>(checkpoints[j + 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... |