제출 #994241

#제출 시각아이디문제언어결과실행 시간메모리
994241vjudge1Sightseeing in Kyoto (JOI22_kyoto)C++17
0 / 100
6 ms8284 KiB
#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) 메시지

kyoto.cpp: In function 'll solve(const std::vector<s>&, const std::vector<s>&)':
kyoto.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<s>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i = 0; i < a.size(); i++) {
      |                     ~~^~~~~~~~~~
kyoto.cpp:23:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<s>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for (int j = 0; j < b.size(); j++) {
      |                         ~~^~~~~~~~~~
kyoto.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<s>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |             if (i < a.size() - 1)
      |                 ~~^~~~~~~~~~~~~~
kyoto.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<s>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             if (j < b.size() - 1)
      |                 ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...