Submission #774036

#TimeUsernameProblemLanguageResultExecution timeMemory
774036kingfran1907Carnival Tickets (IOI20_tickets)C++14
0 / 100
1 ms340 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; typedef long long llint; const int maxn = 1510; int n, m, k; llint pref[maxn][maxn]; int t[maxn]; int ptrl[maxn], ptrr[maxn]; bool bio[maxn]; llint f(int x, int t) { return pref[x][m] - pref[x][m - t] - pref[x][k - t]; } llint cal(int x, int t) { if (t == 0) return (1LL << 60); return f(x, t) - f(x, t - 1); } long long find_maximum(int K, std::vector<std::vector<int>> x) { n = x.size(); m = x[0].size(); k = K; vector< vector<int> > ans(n, vector<int>(m, -1)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) pref[i][j + 1] = pref[i][j] + x[i][j]; set< pair<llint, int> > s; for (int i = 0; i < n; i++) { t[i] = k; s.insert({cal(i, k), i}); } for (int abc = 0; abc < k * n / 2; abc++) { auto iter = s.begin(); int ind = iter->second; s.erase(iter); t[ind]--; s.insert({cal(ind, t[ind]), ind}); } //for (int i = 0; i < n; i++) printf("%d ", t[i]); //printf("\n"); llint sol = 0; for (int i = 0; i < n; i++) sol += f(i, t[i]); for (int i = 0; i < n; i++) { ptrr[i] = 0, ptrr[i] = m - 1; } int mid = n / 2; for (int i = 0; i < k; i++) { vector< pair<int, int> > v; for (int j = 0; j < n; j++) { bio[j] = false; if (ptrl[j] < k - t[j]) v.push_back({x[j][ptrl[j]], j}); } sort(v.begin(), v.end()); int prag = v[mid - 1].first; for (int j = 0; j < mid; j++) { bio[j] = true; int pos = v[j].second; ans[pos][ptrl[pos]++] = i; } v.clear(); for (int j = 0; j < n; j++) { if (ptrr[j] >= m - t[j] && !bio[j]) v.push_back({x[j][ptrr[j]], j}); } sort(v.begin(), v.end()); int ac = mid; for (int j = 0; j < v.size(); j++) { if (ac == 0) break; if (v[j].first >= prag) { ac--; int pos = v[j].second; ans[pos][ptrr[pos]--] = i; } } } allocate_tickets(ans); return sol; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:77:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |   for (int j = 0; j < v.size(); j++) {
      |                   ~~^~~~~~~~~~
#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...