답안 #944012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944012 2024-03-12T06:33:22 Z TAhmed33 Homecoming (BOI18_homecoming) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "homecoming.h"
using namespace std;
typedef long long ll;
const int MAXN = 4e6 + 25;
ll dp[MAXN], pref_a[MAXN], pref_b[MAXN];
ll solve (int n, int k, int *A, int *B) {
    for (int i = 0; i < 2 * n; i++) {
        pref_a[i] = pref_b[i] = dp[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        pref_a[i] = A[i] + (i == 0 ? 0 : pref_a[i - 1]);
    }
    for (int i = 0; i < n + k; i++) {
        pref_b[i] = B[i % k] + (i == 0 ? 0 : pref_b[i - 1]);
    }
    ll ret = 0, cur = 0;
    for (int i = 0; i < n; i++) {
        dp[i] = pref_a[i] - pref_b[i + k - 1] + cur;
        if (i) dp[i] = max(dp[i], dp[i - 1]);
        else dp[i] = max(dp[i], 0);
        cur = max(cur, dp[i] - pref_a[i] + pref_b[i]);
        ret = max(ret, dp[i]);
    }
    cur = 0;
    for (int i = 0; i < n; i++) {
        dp[i] = pref_a[i] - pref_b[i + k - 1] + cur;
        if (i) dp[i] = max(dp[i], dp[i - 1]);
        cur = max(cur, dp[i] - pref_a[i] + pref_b[i]);
    }
    ret = max(ret, dp[n - 1]);
    return ret;
}

Compilation message

homecoming.cpp: In function 'll solve(int, int, int*, int*)':
homecoming.cpp:21:34: error: no matching function for call to 'max(ll&, int)'
   21 |         else dp[i] = max(dp[i], 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 homecoming.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:
homecoming.cpp:21:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   21 |         else dp[i] = max(dp[i], 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 homecoming.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:
homecoming.cpp:21:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   21 |         else dp[i] = max(dp[i], 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 homecoming.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:
homecoming.cpp:21:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   21 |         else dp[i] = max(dp[i], 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 homecoming.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:
homecoming.cpp:21:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   21 |         else dp[i] = max(dp[i], 0);
      |                                  ^