제출 #1015822

#제출 시각아이디문제언어결과실행 시간메모리
1015822aykhn카니발 티켓 (IOI20_tickets)C++17
컴파일 에러
0 ms0 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #define inf 0x3F3F3F3F3F3F3F3F #define int long long long long find_maximum(signed k, vector<vector<signed>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> answer(n, vector<int> (m, -1)); vector<vector<long long>> pre(n, vector<long long> (m, 0)), suf(n, vector<long long> (m, 0)); vector<vector<long long>> dp(n, vector<long long> (k * n / 2 + 5, -inf)), take(n, vector<long long> (k * n / 2 + 5, -1)); vector<long long> taken(n, 0); auto presum = [&](int i, int len) { if (!len) return 0LL; return pre[i][len - 1]; }; auto sufsum = [&](int i, int len) { if (!len) return 0LL; return suf[i][m - len]; }; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) pre[i][j] = (j ? pre[i][j - 1] : 0) + x[i][j]; for (int j = m - 1; j >= 0; j--) suf[i][j] = (j + 1 < m ? suf[i][j + 1] : 0) + x[i][j]; } for (int i = 0; i <= min(k, k * n / 2); i++) { dp[0][i] = sufsum(0, i) - presum(0, k - i); take[0][i] = i; } for (int i = 1; i < n; i++) { for (int j = 0; j <= k * n / 2; j++) { for (int l = 0; l <= k; l++) { if (j - l < 0) continue; if (dp[i - 1][j - l] + sufsum(i, l) - presum(i, k - l) > dp[i][j]) { dp[i][j] = dp[i - 1][j - l] + sufsum(i, l) - presum(i, k - l); take[i][j] = l; } } } } int i = n - 1, j = n * k / 2; int s = 0; while (i >= 0) { taken[i] = take[i][j]; s += taken[i]; j -= take[i][j]; i--; } assert(j == 0); vector<int> o(n, 0); iota(o.begin(), o.end(), 0); vector<int> l(n, 0), r(n, 0); long long mn = -inf, mx = inf; for (int i = 0; i < n; i++) { r[i] = m - taken[i]; for (int j = 0; j < k - taken[i]; j++) mn = max(mn, 1LL * x[i][j]); for (int j = m - 1; j >= r[i]; j--) mx = min(mx, 1LL * x[i][j]); } for (int i = 0; i < n; i++) { for (int j = k - taken[i]; j < m; j++) { assert(x[i][j] >= mn); } } assert(mn <= mx); for (int t = 0; t < k; t++) { sort(o.begin(), o.end(), [&](const int &a, const int &b) { return r[a] < r[b]; }); for (int i = 0; i < o.size() / 2; i++) { assert(r[o[i]] < m); answer[o[i]][r[o[i]]] = t; r[o[i]]++; } for (int i = o.size() / 2; i < o.size(); i++) { answer[o[i]][l[o[i]]] = t; l[o[i]]++; } } allocate_tickets(answer); return dp[n - 1][n * k / 2]; }

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

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:32:39: error: no matching function for call to 'min(int&, long long int)'
   32 |  for (int i = 0; i <= min(k, k * n / 2); i++)
      |                                       ^
In file included from /usr/include/c++/10/vector:60,
                 from tickets.h:1,
                 from tickets.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
tickets.cpp:32:39: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   32 |  for (int i = 0; i <= min(k, k * n / 2); i++)
      |                                       ^
In file included from /usr/include/c++/10/vector:60,
                 from tickets.h:1,
                 from tickets.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
tickets.cpp:32:39: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   32 |  for (int i = 0; i <= min(k, k * n / 2); i++)
      |                                       ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from tickets.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
tickets.cpp:32:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   32 |  for (int i = 0; i <= min(k, k * n / 2); i++)
      |                                       ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from tickets.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
tickets.cpp:32:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   32 |  for (int i = 0; i <= min(k, k * n / 2); i++)
      |                                       ^
tickets.cpp:86:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |   for (int i = 0; i < o.size() / 2; i++)
      |                   ~~^~~~~~~~~~~~~~
tickets.cpp:92:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |   for (int i = o.size() / 2; i < o.size(); i++)
      |                              ~~^~~~~~~~~~
tickets.cpp:98:19: error: could not convert 'answer' from 'vector<vector<long long int>>' to 'vector<vector<int>>'
   98 |  allocate_tickets(answer);
      |                   ^~~~~~
      |                   |
      |                   vector<vector<long long int>>