Submission #421795

#TimeUsernameProblemLanguageResultExecution timeMemory
421795idk321Carnival Tickets (IOI20_tickets)C++17
25 / 100
1014 ms87604 KiB
#include "tickets.h" #include <vector> #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1000000000000000000LL; 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)); if (m == 1) { for (int i = 0; i < n; i++) answer[i][0] = 0; allocate_tickets(answer); vector<int> values(n); for (int i = 0; i < n; i++) { values[i] = x[i][0]; } sort(values.begin(), values.end()); ll res = 0; int mid = (0 + n - 1) / 2; for (int i = 0; i < n; i++) { res += abs(values[mid] - values[i]); } return res; } vector<vector<array<int, 2>>> valAndInd(n, vector<array<int, 2>>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { valAndInd[i][j] = {x[i][j], j}; } } for (int i = 0; i < n; i++) sort(valAndInd[i].begin(), valAndInd[i].end()); int big = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) big = max(big, 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; } /* if (k == 1) { array<int, 3> best = {-1, -1, -1}; vector<array<int, 2>> byVal; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { byVal.push_back({x[i][j], i}); } } sort(byVal.begin(), byVal.end()); vector<array<int, 2>> order; for (int i = 0; i < n; i++) { order.push_back({x[i].front(), i}); } ll cres = 0; for (int i = 0; i < n; i++) { cres += x[i].back() - byVal[0][0]; } ll res = INF; int take = 0; for (auto val : byVal) { int num = val[0]; while (take < n && order[take].front() <= num) { cres -= take++; } } } */ return 1; } /* 3 4 3 1 0 1 1 0 1 0 0 0 0 1 1 */

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:72: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]
   72 |             for (int i = 0; i < n; i++) byFreq.push_back({isAt[i][0].size(), isAt[i][1].size(), i});
      |                                                           ~~~~~~~~~~~~~~~^~
tickets.cpp:72: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]
   72 |             for (int i = 0; i < n; i++) byFreq.push_back({isAt[i][0].size(), isAt[i][1].size(), i});
      |                                                                              ~~~~~~~~~~~~~~~^~
tickets.cpp:56:13: warning: unused variable 'turn' [-Wunused-variable]
   56 |         int turn = 0;
      |             ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...