Submission #760974

#TimeUsernameProblemLanguageResultExecution timeMemory
760974drdilyorCatfish Farm (IOI22_fish)C++17
Compilation error
0 ms0 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]);
    }
    for (int i = 0; i < n; i++)
        sort(arr[i].begin(), arr[i].end());
    auto pref = arr;
    for (int i = 0; i <= n; i++) {
        for (int j = 1; j < (int)pref[i].size(); j++) {
            pref[i][j].second += pref[i][j-1].second;
        }
    }

    auto sum_right = [&](int c, int right)->ll{
        int l = -1, r = pref[c].size();
        while (l < r-1) {
            int mid = (l+r) / 2;
            if (pref[c][mid].first <= right) l = mid;
            else r= mid;
        }
        return l==-1 ? 0 : pref[c][l].second;
    };

    auto sum = [&](int c, int l, int r) { // [l, r]
        if (l <= r) return sum_right(c, r) - sum_right(c, l-1);
        else return 0ll;
    };
    vector<vector<int>> byx(n+2), used(n+1);
    for (int i = 0; i < m; i++)
        byx[x[i]+1].push_back(y[i]);
    for (int i = 0; i <= n; i++) {
        if (i) for (int j : byx[i-1])
            used[i].push_back(j+1);
        if (n-i) for (int j : byx[i+1])
            used[i].push_back(j+1);
        used[i].push_back(0);
        sort(used[i].begin(), used[i].end());
    }


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

}

Compilation message (stderr)

fish.cpp: In lambda function:
fish.cpp:75:30: error: 'h3' was not declared in this scope; did you mean 'h2'?
   75 |             res -= sum(c, 0, h3-1);
      |                              ^~
      |                              h2
fish.cpp:78:25: error: no matching function for call to 'max(ll&, int)'
   78 |         res = max(res, 0);
      |                         ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from fish.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
fish.cpp:78:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   78 |         res = max(res, 0);
      |                         ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from fish.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
fish.cpp:78:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   78 |         res = max(res, 0);
      |                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from fish.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
fish.cpp:78:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   78 |         res = max(res, 0);
      |                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from fish.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
fish.cpp:78:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   78 |         res = max(res, 0);
      |                         ^