제출 #1196363

#제출 시각아이디문제언어결과실행 시간메모리
1196363GabpCarnival Tickets (IOI20_tickets)C++20
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> #include"tickets.h" using namespace std; long long int find_maximum(int k, vector<vector<int>> x) { int n = x.size(), m = x[0].size(); long long int total = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { total += x[i][m - j - 1]; } } vector<int> idx(n, 0); priority_queue<pair<long long int,int>> pq; for (int i = 0; i < n; i++) pq.push({-x[i][0] - x[i][m - k - 1], i}); int cnt = n * k / 2; while (cnt--) { auto [val, id] = pq.top(); pq.pop(); total += val; idx[id]++; if (idx[id] < k) { pq.push({-x[i][idx[id]] - x[i][m - k - 1 + idx[id]], i}); } } vector<int> lo = idx; vector<int> hi(n); for (int i = 0; i < n; i++) hi[i] = k - lo[i]; vector<vector<int>> ans(n, vector<int>(m, -1)); for (int i = 0; i < k; i++) { int l = n / 2, r = n / 2; for (int j = 0; j < n; j++) { if (lo[j] == 0) { ans[j][m - hi[j]] = i; hi[j]--; r--; } else if (hi[j] == 0) { lo[j]--; ans[j][lo[j]] = i; l--; } } for (int j = 0; j < n; j++) { if (lo[j] + hi[j] != k - i) continue; if (l) { lo[j]--; ans[j][lo[j]] = i; l--; } else { ans[j][m - hi[j]] = i; hi[j]--; r--; } } } allocate_tickets(ans); return total; }

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

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:23:19: error: 'i' was not declared in this scope; did you mean 'id'?
   23 |       pq.push({-x[i][idx[id]] - x[i][m - k - 1 + idx[id]], i});
      |                   ^
      |                   id
tickets.cpp:23:14: error: no matching function for call to 'std::priority_queue<std::pair<long long int, int> >::push(<brace-enclosed initializer list>)'
   23 |       pq.push({-x[i][idx[id]] - x[i][m - k - 1 + idx[id]], i});
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:86,
                 from tickets.cpp:1:
/usr/include/c++/11/bits/stl_queue.h:640:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<long long int, int>; _Sequence = std::vector<std::pair<long long int, int>, std::allocator<std::pair<long long int, int> > >; _Compare = std::less<std::pair<long long int, int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<long long int, int>]'
  640 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/11/bits/stl_queue.h:640:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<long long int, int>&'}
  640 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_queue.h:648:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(std::priority_queue<_Tp, _Sequence, _Compare>::value_type&&) [with _Tp = std::pair<long long int, int>; _Sequence = std::vector<std::pair<long long int, int>, std::allocator<std::pair<long long int, int> > >; _Compare = std::less<std::pair<long long int, int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<long long int, int>]'
  648 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/11/bits/stl_queue.h:648:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<long long int, int> >::value_type&&' {aka 'std::pair<long long int, int>&&'}
  648 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~