Submission #1331242

#TimeUsernameProblemLanguageResultExecution timeMemory
1331242michael12Boxes with souvenirs (IOI15_boxes)C++20
Compilation error
0 ms0 KiB
#include "boxes.h"
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define endl '\n'
using namespace std;
const int maxn = 1e6 + 5;
const int inf = 1e9 + 5;
long long delivery(int N, int K, int L, int p[]){
    long long cur = 0;
    vector<int> ps(N);
    for(int i = 0; i < N; i++){
        ps[i] = p[i];
    }
    vector<int> dp(N), dp1(N);
    for(int i = 0; i < N; i++){
        if(i >= K){
            dp[i] = dp[i - K] + min(ps[i] * 2, L);
        }
        else{
            dp[i] = min(ps[i] * 2, L);
        }
    }
    long long ans = 0;
    for(int i = N - 1; i >= 0; i--){
        if(i + K < N){
            dp1[i] = dp1[i + K] + min(2 * (L - ps[i]), L);
        }
        else{
            dp1[i] = min(2 * (L - ps[i]), L);
        }
    }
    ans = min(dp[N - 1], dp1[0]);
    for(int i = 0; i < N - 1; i++){
        ans = min(ans, dp[i] + dp[i + 1]);
    }
    return ans;
}
// signed main(){
//     int n, k, l;
//     cin >> n >> k >> l;
//     int a[n];
//     for(int i = 0; i < n; i++){
//         cin >> a[i];
//     }
//     cout << delivery(n, k, l, a);

// }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:36:18: error: no matching function for call to 'min(long long int&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type)'
   36 |         ans = min(ans, dp[i] + dp[i + 1]);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from boxes.cpp:2:
/usr/include/c++/13/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
boxes.cpp:36:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   36 |         ans = min(ans, dp[i] + dp[i + 1]);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:281:5: note:   template argument deduction/substitution failed:
boxes.cpp:36:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   36 |         ans = min(ans, dp[i] + dp[i + 1]);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5775:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5775 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5775:5: note:   template argument deduction/substitution failed:
boxes.cpp:36:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   36 |         ans = min(ans, dp[i] + dp[i + 1]);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5785:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5785 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5785:5: note:   template argument deduction/substitution failed:
boxes.cpp:36:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   36 |         ans = min(ans, dp[i] + dp[i + 1]);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~