제출 #1343378

#제출 시각아이디문제언어결과실행 시간메모리
1343378jmuzhen메기 농장 (IOI22_fish)C++20
컴파일 에러
0 ms0 KiB
#include "fish.h"

#include <vector>
#include<bits/stdc++.h>
using namespace std;

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
  bool is_sub1=1, is_sub2=1, is_sub3 = 1;
  for (int i = 0; i < M; i++) {
    if (X[i] % 2 != 0) is_sub1 = 0;
    if (X[i] > 1) is_sub2 = 0;
    if (Y[i] != 0) is_sub3 = 0;
  }

  if (is_sub1) {
    long long ans = 0;
    for (int i = 0; i < M; i++) ans += W[i];
    return ans;
  }
  else if (is_sub2) {
    long long col0 = 0, col1 = 0;
    for (int i = 0; i < M; i++) {
      if (X[i] == 0) col0 += W[i];
      else col1 += W[i];
    }
    return max(col0, col1);
  }
  else if (is_sub3) {
    int dp[100000+10][2][2]; // {prev built, next built}
    vector<bool> w(N, 0);
    for (int i = 0; i < M; i++) {
      w[X[i]] = W[i];
    }

    for (int i = 0; i < N; i++) {
      for (int prevb = 0; prevb <= 1; prevb++) {
        for (int nextb = 0; nextb <= 1; nextb++) {
          // prune
          if (i == 0 && prevb) continue;
          if (i == N-1 && nextb) continue;

          // case1. don't build
          int case1 = 0;
          {
            if ((prevb || nextb)) {
              // can take this one
              // case1a:take here
              if (i>0) {
                case1 = max(case1, w[i] + max(dp[i-1][0][0], dp[i-1][1][0]));
              }
              else {
                case1 = max(case1, w[i]);
              }
            }
          }
          // case2. build
          int case2 = 0;
          {
            if (i > 0) {
              case2 = max(case2, max(dp[i-1][0][1], dp[i-1][1][1]));
            }
          }
        }
      } // end dp

    } // for (N) loop


    return max(dp[N-1][0][0],dp[N-1][1][0]);
  }
}

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

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:53:28: error: no matching function for call to 'max(int&, std::vector<bool>::reference)'
   53 |                 case1 = max(case1, w[i]);
      |                         ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/13/vector:62,
                 from fish.h:1,
                 from fish.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
fish.cpp:53:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<bool>::reference')
   53 |                 case1 = max(case1, w[i]);
      |                         ~~~^~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
fish.cpp:53:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<bool>::reference')
   53 |                 case1 = max(case1, w[i]);
      |                         ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from fish.cpp:4:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
fish.cpp:53:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   53 |                 case1 = max(case1, w[i]);
      |                         ~~~^~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
fish.cpp:53:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   53 |                 case1 = max(case1, w[i]);
      |                         ~~~^~~~~~~~~~~~~
fish.cpp:72:1: warning: control reaches end of non-void function [-Wreturn-type]
   72 | }
      | ^