제출 #1126935

#제출 시각아이디문제언어결과실행 시간메모리
1126935fzyzzz_zMarathon Race 2 (JOI24_ho_t3)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std; 

using ll = long long; 

const int N = 5e5 + 10; 
const int A = 1001; 
const ll inf = (1LL << 61); 

inline void amin(ll & x, ll y) { 
    if (y < x) x = y; 
}

#define int ll

int f[N]; 
ll dp[2][A][A]; 
ll cost[2][A]; 

int32_t main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(0); 

    int N, L; 
    cin >> N >> L; 
    vector<int> X(N); 
    for (auto & x: X) cin >> x; 

    sort(X.begin(), X.end()); 
    vector<pair<int, int>> a(1, {X[0], 0}); 
    for (auto x: X) {
        if (x == a.back().first) a.back().second++; 
        else a.emplace_back(x, 1); 
    }
    int q; 
    cin >> q; 
    int n = a.size(); 
    if (n > 1000) {
        while (q--) {
            cout << "No\n"; 
        }
        exit(0); 
    }

    for (int i = 0; i <= L + 1; ++i) f[i] = 0; 
    for (auto [x, c]: a) f[x + 1] += c; 
    for (int i = 0; i <= L; ++i) f[i + 1] += f[i]; 

    for (int t = 0; t < 2; ++t) {
        for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) dp[0][i][j] = dp[1][i][j] = inf; 
        dp[t][0][n - 1] = 0; // accounted for all outside of (i, j), at 0L or 1R 

        for (int len = n - 1; len > 0; --len) {
            for (int l = 0, r = len; r < n; l++, r++) {
                ll has = 0; 
                ll pl = a[l].first; 
                ll pl1 = a[l + 1].first; 
                ll pr1 = a[r - 1].first; 
                ll pr = a[r].first;   
                has += f[pl]; 
                has += f[L + 1] - f[pr + 1]; 
                has++; 
                
                amin(dp[0][l + 1][r], dp[0][l][r] + (has + a[l].second) * (pl1 - pl)); 
                amin(dp[1][l][r - 1], dp[0][l][r] + (has) * (2LL * pr - pl - pl1) + 1LL * a[r].second * (pr - pr1)); 
                
                
                amin(dp[1][l][r - 1], dp[1][l][r] + (has + a[r].second) * (pr - pr1)); 
                amin(dp[0][l + 1][r], dp[1][l][r] + (has) * (pr + pr1 - 2LL * pl) + 1LL * a[l].second * (pl1 - pl));     
                
            }
        }
        for (int i = 0; i < n; ++i) {
            cost[t][i] = dp[t][i][i]; 
        }
    }

    while (q--) {
        int st, en; 
        ll t; 
        cin >> st >> en >> t; 
        t -= f[L + 1]; 

        int lo = 0, hi = n - 1; 
        while (lo < hi) {
            int md = (lo + hi) / 2; 
            if (a[md].first >= en) hi = md; 
            else lo = md + 1; 
        }
        ll ans = inf; 
        for (int i = max(0, lo - 3); i <= min(n - 1, lo + 3); ++i) {
            amin(ans, cost[0][i] + abs(st - a[0].first) + (ll) (f[L + 1] + 1) * (abs(en - a[n - 1].first))); 
            amin(ans, cost[1][i] + abs(st - a[n - 1].first) + (ll) (f[L + 1] + 1) * (abs(en - a[0].first))); 
        }

        if (ans <= t) {
            cout << "Yes\n"; 
        } else {
            cout << "No\n"; 
        }
    }


}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int32_t main()':
Main.cpp:91:25: error: no matching function for call to 'max(int, ll)'
   91 |         for (int i = max(0, lo - 3); i <= min(n - 1, lo + 3); ++i) {
      |                      ~~~^~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/11/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++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
Main.cpp:91:25: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   91 |         for (int i = max(0, lo - 3); i <= min(n - 1, lo + 3); ++i) {
      |                      ~~~^~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/11/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++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
Main.cpp:91:25: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   91 |         for (int i = max(0, lo - 3); i <= min(n - 1, lo + 3); ++i) {
      |                      ~~~^~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from Main.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
Main.cpp:91:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   91 |         for (int i = max(0, lo - 3); i <= min(n - 1, lo + 3); ++i) {
      |                      ~~~^~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from Main.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
Main.cpp:91:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   91 |         for (int i = max(0, lo - 3); i <= min(n - 1, lo + 3); ++i) {
      |                      ~~~^~~~~~~~~~~