Submission #837520

#TimeUsernameProblemLanguageResultExecution timeMemory
837520KerimCarnival Tickets (IOI20_tickets)C++17
Compilation error
0 ms0 KiB
#include "tickets.h" #include <vector> #include <bits/stdc++.h> typedef long long int ll; using namespace std; long long find_maximum(int k, vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); ll sum = 0; vector <vector <int>> ans(n, vector <int> (m, -1)); vector <set<pair<int,int>>> rows(n); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) rows[i].insert({x[i][j], j}); for (int i = 0; i < k; i++){ ll cur = 0; vector <pair<ll, int>> ticket; for (int j = 0; j < n; j++){ pair<int, int> l = *rows[j].begin(); pair<int, int> r = *rows[j].rbegin(); cur = -l.first - r.first; ticket.push_back({cur, j}); cur += r.first; } sort(ticket.begin(), ticket.end(), greater<pair<ll, int>>()); for (int j = 0; j < n/2; j++){ cur += ticket[j].first; int pos = ticket[j].second; pair<int, int> ans_pos = *rows[pos].begin(); ans[pos][ans_pos.second] = i; } for (int j = 0; j < n; j++){ pair<int, int> ans_pos = *rows[j].begin(); pair<int, int> ans_pos_r = *rows[j].rbegin(); if (ans[j][ans_pos.second] != i){ ans[j][ans_pos_r.second] = i; } } for (int j = 0; j < n; j++){ rows[j].erase(rows[j].begin()); if (!rows[j].empty()) rows[j].erase(rows[j].rbegin()); } sum = max(sum, cur); } allocate_tickets(ans); return sum; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:43:35: error: no matching function for call to 'std::set<std::pair<int, int> >::erase(std::set<std::pair<int, int> >::reverse_iterator)'
   43 |     rows[j].erase(rows[j].rbegin());
      |                                   ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from tickets.cpp:3:
/usr/include/c++/10/bits/stl_set.h:654:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(std::set<_Key, _Compare, _Alloc>::const_iterator) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator]'
  654 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/10/bits/stl_set.h:654:28: note:   no known conversion for argument 1 from 'std::set<std::pair<int, int> >::reverse_iterator' {aka 'std::reverse_iterator<std::_Rb_tree_const_iterator<std::pair<int, int> > >'} to 'std::set<std::pair<int, int> >::const_iterator' {aka 'std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator'}
  654 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:684:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::size_type = long unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<int, int>]'
  684 |       erase(const key_type& __x)
      |       ^~~~~
/usr/include/c++/10/bits/stl_set.h:684:29: note:   no known conversion for argument 1 from 'std::set<std::pair<int, int> >::reverse_iterator' {aka 'std::reverse_iterator<std::_Rb_tree_const_iterator<std::pair<int, int> > >'} to 'const key_type&' {aka 'const std::pair<int, int>&'}
  684 |       erase(const key_type& __x)
      |             ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:706:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::const_iterator) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator]'
  706 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/10/bits/stl_set.h:706:7: note:   candidate expects 2 arguments, 1 provided