Submission #760956

#TimeUsernameProblemLanguageResultExecution timeMemory
760956drdilyor메기 농장 (IOI22_fish)C++17
0 / 100
691 ms2097152 KiB
#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
using ll = long long;

ll max_weights(
    int n, int m, vector<int> x, vector<int> y, vector<int> w) {
    vector arr(n+1, vector<pair<int,ll>>());
    for (int i = 0; i < m; i++) {
        arr[x[i]+1].emplace_back(y[i], w[i]);
    }
    auto pref = arr;
    for (int i = 0; i <= n; i++) {
        pref[i] = arr[i];
        for (int j = 1; j < pref[i].size(); j++) {
            pref[i][j].second += pref[i][j-1].second;
        }
    }

    auto sum = [&](int c, int l, int r) { // [l, r]
        auto li = upper_bound(pref[c].begin(), pref[c].end(),
                pair{l, 0ll});
        auto ri = upper_bound(pref[c].begin(), pref[c].end(),
                pair{r, ll(1e18)});
        ll ls = li != pref[c].begin() ? (--li)->second : 0;
        ll rs = ri != pref[c].begin() ? (--ri)->second : 0;
        if (l <= r) return rs - ls;
        else return 0ll;
    };

    vector memo(2, vector(n+1, vector(n+1, -1ll)));
    auto dp = [&](auto& dp, bool inc, int c, int h2)->ll{
        if (c == n+1) return 0;
        ll& res = memo[inc][c][h2];
        if (res!=-1) return res;
        res = 0;
        if (inc) {
            for (int h3 = h2; h3 <= n; h3++) {
                ll val = sum(c-1, h2, h3-1) + sum(c, h3, h2-1);
                res = max(res, val + dp(dp, true, c+1, h3));
                res = max(res, val + dp(dp, false, c+1, h3));
            }
        } else {
            for (int h3 = 0; h3 <= h2; h3++) {
                ll val = sum(c-1, h2, h3-1) + sum(c, h3, h2-1);
                res = max(res, val + dp(dp, false, c+1, h3));
            }
        }
        res = max(res, dp(dp, true, c+1, 0));
        return res;
    };
    ll res = dp(dp, true, 1, 0);
    return res;

}

Compilation message (stderr)

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:15:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for (int j = 1; j < pref[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...