Submission #422066

#TimeUsernameProblemLanguageResultExecution timeMemory
422066idk321Carnival Tickets (IOI20_tickets)C++17
Compilation error
0 ms0 KiB
#include "tickets.h" #include <vector> #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1000000000000000000LL; struct Comp { bool operator() (const array<int, 4>& ar1, const array<int, 4>& ar2) const { return ar1[3] < ar2[3]; } }; long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> answer; answer.resize(n, vector<int>(m, -1)); int cmax = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cmax = max(cmax, x[i][j]); } } if (big <= 1) { int turn = 0; vector<vector<vector<int>>> isAt(n, vector<vector<int>>(2)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { isAt[i][x[i][j]].push_back(j); } } int res = 0; for (int a = 0; a < k; a++) { vector<array<int, 3>> byFreq; for (int i = 0; i < n; i++) byFreq.push_back({isAt[i][0].size(), isAt[i][1].size(), i}); sort(byFreq.rbegin(), byFreq.rend()); int f0 = 0; int f1 = 0; for (int i = 0; i < n / 2; i++) { int node = byFreq[i][2]; if (!isAt[node][0].empty()) { answer[node][isAt[node][0].back()] = a; isAt[node][0].pop_back(); f0++; } else { answer[node][isAt[node][1].back()] = a; isAt[node][1].pop_back(); f1++; } } for (int i = n / 2; i < n; i++) { int node = byFreq[i][2]; if (!isAt[node][1].empty()) { answer[node][isAt[node][1].back()] = a; isAt[node][1].pop_back(); f1++; } else { answer[node][isAt[node][0].back()] = a; isAt[node][0].pop_back(); f0++; } } res += min(f1, f0); } allocate_tickets(answer); return res; } priority_queue<array<int, 4>, vector<array<int, 4>>, Comp> pq; vector<vector<int>> type(n, vector<int>(m)); ll res = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { res -= x[i][j]; type[i][j] = -1; } for (int j = m - 1, l = k - 1; l >= 0; l--, j--) { pq.push({l, j, i, x[i][j] + x[i][l]}); } } for (int i = 0; i < n * k / 2; i++) { auto cur = pq.top(); pq.pop(); res += cur[3]; type[cur[2]][cur[0]] = 0; type[cur[2]][cur[1]] = 1; } vector<vector<int>> small(n); vector<vector<int>> big(n); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (type[i][j] == -1) small[i].push_back(j); if (type[i][j] == 1) big[i].push_back(j); } } for (int a = 0; a < k; a++) { vector<array<int, 3>> byFreq; for (int i = 0; i < n; i++) { byFreq.push_back({small[i].size(), big[i].size(), i}); } sort(byFreq.rbegin(), byFreq.rend()); for (int i = 0; i < n / 2; i++) { int y = byFreq[i][2]; answer[y][small[y].back()] = a; small[y].pop_back(); } for (int i = n / 2; i < n; i++) { int y = byFreq[i][2]; answer[y][big[y].back()] = a; big[y].pop_back(); } } allocate_tickets(answer); return res; } /* 5 3 1 1 8 1000 1 3 4 3 5 6 2 5 7 1 5 10 */

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:33:13: error: 'big' was not declared in this scope
   33 |         if (big <= 1)
      |             ^~~
tickets.cpp:51:74: warning: narrowing conversion of '(&(& isAt.std::vector<std::vector<std::vector<int> > >::operator[](((std::vector<std::vector<std::vector<int> > >::size_type)i)))->std::vector<std::vector<int> >::operator[](0))->std::vector<int>::size()' from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   51 |             for (int i = 0; i < n; i++) byFreq.push_back({isAt[i][0].size(), isAt[i][1].size(), i});
      |                                                           ~~~~~~~~~~~~~~~^~
tickets.cpp:51:93: warning: narrowing conversion of '(&(& isAt.std::vector<std::vector<std::vector<int> > >::operator[](((std::vector<std::vector<std::vector<int> > >::size_type)i)))->std::vector<std::vector<int> >::operator[](1))->std::vector<int>::size()' from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   51 |             for (int i = 0; i < n; i++) byFreq.push_back({isAt[i][0].size(), isAt[i][1].size(), i});
      |                                                                              ~~~~~~~~~~~~~~~^~
tickets.cpp:35:13: warning: unused variable 'turn' [-Wunused-variable]
   35 |         int turn = 0;
      |             ^~~~
tickets.cpp:139:44: warning: narrowing conversion of '(& small.std::vector<std::vector<int> >::operator[](((std::vector<std::vector<int> >::size_type)i)))->std::vector<int>::size()' from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
  139 |             byFreq.push_back({small[i].size(), big[i].size(), i});
      |                               ~~~~~~~~~~~~~^~
tickets.cpp:139:59: warning: narrowing conversion of '(& big.std::vector<std::vector<int> >::operator[](((std::vector<std::vector<int> >::size_type)i)))->std::vector<int>::size()' from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
  139 |             byFreq.push_back({small[i].size(), big[i].size(), i});
      |                                                ~~~~~~~~~~~^~