Submission #994250

# Submission time Handle Problem Language Result Execution time Memory
994250 2024-06-07T09:51:40 Z vjudge1 Sightseeing in Kyoto (JOI22_kyoto) C++17
0 / 100
1 ms 348 KB
#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 first_smallest = 0;
    ll last_smallest = 0;
    for (int i = 0; i < a.size(); i++) {
        if (a[i].value < a[first_smallest].value)
            first_smallest = i;

        if (a[i].value <= a[last_smallest].value)
            last_smallest = i;
    }

    ret.push_back(a[0]);
    for (int i = 1; i < first_smallest; i++)
        if (a[i].value < ret.back().value)
            ret.push_back(a[i]);

    if (ret.back().pos != first_smallest)
        ret.push_back(a[first_smallest]);

    if (ret.back().pos != last_smallest)
        ret.push_back(a[last_smallest]);

    for (int i = last_smallest + 1; i < a.size() - 1; i++)
        if (a[i].value > ret.back().value)
            ret.push_back(a[i]);

    if (ret.back().pos != a.size() - 1)
        ret.push_back(a.back());

    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";
}

Compilation message

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)
      |                 ~~^~~~~~~~~~~~~~
kyoto.cpp: In function 'std::vector<s> compress(const std::vector<s>&)':
kyoto.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<s>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i = 0; i < a.size(); i++) {
      |                     ~~^~~~~~~~~~
kyoto.cpp:59:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<s>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i = last_smallest + 1; i < a.size() - 1; i++)
      |                                     ~~^~~~~~~~~~~~~~
kyoto.cpp:63:24: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<s>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     if (ret.back().pos != a.size() - 1)
      |         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -