Submission #364791

#TimeUsernameProblemLanguageResultExecution timeMemory
364791wind_reaperCarnival Tickets (IOI20_tickets)C++17
Compilation error
0 ms0 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> ans(n, vector<int>(m, -1)); long long a = 0; for(int i = 0; i < n; i++){ for(int j = m-1; j >= m-k; --j){ ans[i][j] = (m-1-j); a += 1LL*x[i][j]; } } vector<array<int, 4>> b; for(int i = 0; i < n; i++){ for(int j = 0; j < k; j++) for(int w = m-1; w >= m-k; --w) if(i == j){ b.push_back({0, i, j, w}); continue; } b.push_back({x[i][j] + x[i][w], i, j, w}); } sort(b.begin(), b.end()); for(auto& [red, row, mn, mx] : b){ if(ans[row][mx] == -1 || ans[row][mn] != -1) continue; a -= 1LL*red; swap(ans[row][mx], ans[row][mn]); } allocate_tickets(ans); return a; } /* for every i, j < k exchange the i th minimum and j th maximum each exchange costs x[i] + x[j] ... take the first nk/2 valid exchanges the actual order of the stuff doesnt matter you wanna choose nk/2 pairs to remove what happens when the stuff starts to overlap ...|..|... ..|.|.. */

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:25:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   25 |    for(int w = m-1; w >= m-k; --w)
      |    ^~~
tickets.cpp:30:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   30 |     b.push_back({x[i][j] + x[i][w], i, j, w});
      |     ^
tickets.cpp:30:23: error: 'j' was not declared in this scope
   30 |     b.push_back({x[i][j] + x[i][w], i, j, w});
      |                       ^
tickets.cpp:30:33: error: 'w' was not declared in this scope
   30 |     b.push_back({x[i][j] + x[i][w], i, j, w});
      |                                 ^
tickets.cpp:30:45: error: no matching function for call to 'std::vector<std::array<int, 4> >::push_back(<brace-enclosed initializer list>)'
   30 |     b.push_back({x[i][j] + x[i][w], i, j, w});
      |                                             ^
In file included from /usr/include/c++/9/vector:67,
                 from tickets.h:1,
                 from tickets.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1184:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::array<int, 4>; _Alloc = std::allocator<std::array<int, 4> >; std::vector<_Tp, _Alloc>::value_type = std::array<int, 4>]'
 1184 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1184:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::array<int, 4>&'}
 1184 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1200:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::array<int, 4>; _Alloc = std::allocator<std::array<int, 4> >; std::vector<_Tp, _Alloc>::value_type = std::array<int, 4>]'
 1200 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1200:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::array<int, 4> >::value_type&&' {aka 'std::array<int, 4>&&'}
 1200 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~