제출 #1237104

#제출 시각아이디문제언어결과실행 시간메모리
1237104ericl23302나일강 (IOI24_nile)C++20
컴파일 에러
0 ms0 KiB
#include "nile.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define pl pair<ll, ll>
#define pll pair<ll, pl>
#define ppl pair<pl, pl>

std::vector<long long> calculate_costs(std::vector<int> W, std::vector<int> A, std::vector<int> B, std::vector<int> E) {
    int Q = E.size();
    std::vector<long long> R(Q, 0);

    int n = W.size();
    assert(n <= 1000)
    vector<pair<ll, pair<ll, ll>>> items(n);
    for (int i = 0; i < n; ++i) items[i] = {W[i], {A[i], B[i]}};
    sort(items.begin(), items.end());

    vector<ll> benefit(n);
    for (int i = 0; i < n; ++i) benefit[i] = items[i].second.first - items[i].second.second;

    int idx = 0;
    for (auto &d : E) {
        vector<pll> dp(n + 1, {LLONG_MAX / 2, {LLONG_MAX / 2, -1}}); // {no unused: minCost, {one unused: minCost, one unused: index}}
        dp[0] = {0, {LLONG_MAX / 2, -1}};
        for (int i = 1; i <= n; ++i) {
            dp[i].first = dp[i - 1].first + items[i - 1].second.first;
            if (i < n && items[i].first - items[i - 1].first <= d) {
                // do nothing with current item
                dp[i].second = {dp[i - 1].first + items[i - 1].second.first, i - 1};
                if (dp[i - 1].second.first < LLONG_MAX / 2) {
                    pl other = {dp[i - 1].second.first + items[i - 1].second.first, i - 1};
                    if (items[i].first - items[dp[i - 1].second.second].first <= d && benefit[dp[i - 1].second.second] > benefit[i - 1]) other.second = dp[i - 1].second.second;
                    if (other.first < dp[i].second.first || (other.first == dp[i].second.first && benefit[other.second] > benefit[dp[i].second.second])) dp[i].second = other;
                }
            } 

            // combine with one unused
            if (dp[i - 1].second.first < LLONG_MAX / 2) dp[i].first = min(dp[i].first, dp[i - 1].second.first - items[dp[i - 1].second.second].second.first + items[dp[i - 1].second.second].second.second + items[i - 1].second.second);
        }

        R[idx++] = min(dp[n].first, dp[n].second.first);
    }

    return R;
    
}

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

nile.cpp: In function 'std::vector<long long int> calculate_costs(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
nile.cpp:17:5: error: expected ';' before 'vector'
   17 |     vector<pair<ll, pair<ll, ll>>> items(n);
      |     ^~~~~~
nile.cpp:18:33: error: 'items' was not declared in this scope
   18 |     for (int i = 0; i < n; ++i) items[i] = {W[i], {A[i], B[i]}};
      |                                 ^~~~~
nile.cpp:19:10: error: 'items' was not declared in this scope
   19 |     sort(items.begin(), items.end());
      |          ^~~~~
nile.cpp:32:83: error: no match for 'operator=' (operand types are 'std::pair<long long int, long long int>' and '<brace-enclosed initializer list>')
   32 |                 dp[i].second = {dp[i - 1].first + items[i - 1].second.first, i - 1};
      |                                                                                   ^
In file included from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/vector:60,
                 from nile.h:1,
                 from nile.cpp:1:
/usr/include/c++/11/bits/stl_pair.h:418:9: note: candidate: 'template<class _U1, class _U2> constexpr typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = long long int; _T2 = long long int]'
  418 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/11/bits/stl_pair.h:418:9: note:   template argument deduction/substitution failed:
nile.cpp:32:83: note:   couldn't deduce template parameter '_U1'
   32 |                 dp[i].second = {dp[i - 1].first + items[i - 1].second.first, i - 1};
      |                                                                                   ^
In file included from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/vector:60,
                 from nile.h:1,
                 from nile.cpp:1:
/usr/include/c++/11/bits/stl_pair.h:430:9: note: candidate: 'template<class _U1, class _U2> constexpr typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = long long int; _T2 = long long int]'
  430 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/11/bits/stl_pair.h:430:9: note:   template argument deduction/substitution failed:
nile.cpp:32:83: note:   couldn't deduce template parameter '_U1'
   32 |                 dp[i].second = {dp[i - 1].first + items[i - 1].second.first, i - 1};
      |                                                                                   ^
In file included from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/vector:60,
                 from nile.h:1,
                 from nile.cpp:1:
/usr/include/c++/11/bits/stl_pair.h:390:7: note: candidate: 'constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type) [with _T1 = long long int; _T2 = long long int; typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type = const std::pair<long long int, long long int>&]'
  390 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_pair.h:393:55: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, const std::pair<long long int, long long int>&, const std::__nonesuch&>::type' {aka 'const std::pair<long long int, long long int>&'}
  390 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~                  
  391 |                 __and_<is_copy_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        
  392 |                        is_copy_assignable<_T2>>::value,
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  393 |                 const pair&, const __nonesuch&>::type __p)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_pair.h:401:7: note: candidate: 'constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type) [with _T1 = long long int; _T2 = long long int; typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type = std::pair<long long int, long long int>&&]'
  401 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_pair.h:404:45: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, std::pair<long long int, long long int>&&, std::__nonesuch&&>::type' {aka 'std::pair<long long int, long long int>&&'}
  401 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~        
  402 |                 __and_<is_move_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  403 |                        is_move_assignable<_T2>>::value,
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  404 |                 pair&&, __nonesuch&&>::type __p)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
nile.cpp:34:90: error: could not convert '{<expression error>, (i - 1)}' from '<brace-enclosed initializer list>' to 'std::pair<long long int, long long int>'
   34 |                     pl other = {dp[i - 1].second.first + items[i - 1].second.first, i - 1};
      |                                                                                          ^
      |                                                                                          |
      |                                                                                          <brace-enclosed initializer list>