Submission #304364

#TimeUsernameProblemLanguageResultExecution timeMemory
304364AlanCCarnival Tickets (IOI20_tickets)C++14
Compilation error
0 ms0 KiB
#include "tickets.h" #include <vector> #include <algorithm> #include <queue> #define N 1505 using namespace std; int n, m, k, cnt = 0, low[N], high[N], used[N]; vector<vector<int>> answer, a; long long int total = 0; struct Dat { long long int sum; int col, pos; Dat(){} Dat(long long int s, int c, int p) { sum = s; col = c; pos = p; } bool operator < (const Dat &d) { return sum < d.sum; } } D[N * N]; vector<pair<int, int>> small, large; void prepDat() { for (int i=0; i<n; i++) { for (int j=0; j<k; j++) { D[cnt++] = Dat(a[i][j] + a[i][m-k+j], i, j); } } } void generateAnswer() { for (int i=0; i<n; i++) low[i] = 0; for (int i=0; i<cnt/2; i++) low[D[i].col] = max(low[D[i].col], D[i].pos + 1); for (int i=0; i<n; i++) high[i] = k - low[i]; small.clear(); large.clear(); for (int i=0; i<n; i++) if (low[i] > 0) small.push_back(make_pair(low[i], i)); for (int i=0; i<n; i++) if (high[i] > 0) large.push_back(make_pair(high[i], i)); for (int i=0; i<n; i++) { vector<int> row(m, -1); answer.push_back(row); //printf("[%d] %d %d\n", i, low[i], high[i]); } sort(small.begin(), small.end(), greater<pair<int, int>>()); sort(large.begin(), large.end(), greater<pair<int, int>>()); for (int i=0; i<k; i++) { for (int j=0; j<n; j++) used[j] = 0; int x = 0, y = 0; for (int j=0; j<n/2; j++) { while (used[small[x].second] && x < small.size()) x++; if (x == small.size()) while (true) {} used[small[x].second] = 1; while (used[large[y].second] && y < large.size()) y++; if (y == large.size()) while (true) {a[n * 1000] = 1;} used[large[y].second] = 1; int c1 = small[x].second, c2 = large[y].second; int p1 = small[x].first - 1, p2 = m - large[y].first; //printf("[%d %d], [%d %d]\n", c1, p1, c2, p2); answer[c1][p1] = i; answer[c2][p2] = i; total += a[c2][p2] - a[c1][p1]; low[c1]--; high[c2]--; } small.clear(); large.clear(); for (int j=0; j<n; j++) if (low[j] > 0) small.push_back(make_pair(low[j], j)); for (int j=0; j<n; j++) if (high[j] > 0) large.push_back(make_pair(high[j], j)); sort(small.begin(), small.end(), greater<pair<int, int>>()); sort(large.begin(), large.end(), greater<pair<int, int>>()); } } long long find_maximum(int K, vector<vector<int>> x) { n = x.size(); m = x[0].size(); k = K; a = x; prepDat(); sort(D, D + cnt); generateAnswer(); allocate_tickets(answer); return total; }

Compilation message (stderr)

tickets.cpp: In function 'void generateAnswer()':
tickets.cpp:65:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |    while (used[small[x].second] && x < small.size()) x++;
      |                                    ~~^~~~~~~~~~~~~~
tickets.cpp:66:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |    if (x == small.size()) while (true) {}
      |        ~~^~~~~~~~~~~~~~~
tickets.cpp:68:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |    while (used[large[y].second] && y < large.size()) y++;
      |                                    ~~^~~~~~~~~~~~~~
tickets.cpp:69:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |    if (y == large.size()) while (true) {a[n * 1000] = 1;}
      |        ~~^~~~~~~~~~~~~~~
tickets.cpp:69:55: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} and 'int')
   69 |    if (y == large.size()) while (true) {a[n * 1000] = 1;}
      |                                                       ^
In file included from /usr/include/c++/9/vector:72,
                 from tickets.h:1,
                 from tickets.cpp:1:
/usr/include/c++/9/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'int' to 'const std::vector<int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
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:706:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:706:26: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>&&'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:727:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  727 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:727:46: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'
  727 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~