Submission #315601

#TimeUsernameProblemLanguageResultExecution timeMemory
315601VEGAnnCarnival Tickets (IOI20_tickets)C++14
100 / 100
894 ms60540 KiB
#include "tickets.h" #include <bits/stdc++.h> #define PB push_back #define sz(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define i2 array<int,2> using namespace std; typedef long long ll; const int N = 1600; const ll OO = 1e18; priority_queue<i2> pq; int ptr[N]; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> answer; for (int i = 0; i < n; i++) { std::vector<int> row(m); fill(all(row), -1); answer.push_back(row); } ll ans = 0; for (int i = 0; i < n; i++){ for (int j = 0; j < k; j++) ans += x[i][m - k + j]; ptr[i] = 0; pq.push({-x[i][m - k] - x[i][0], i}); } // add again to pq only if ptr < m for (int itr = (n / 2) * k; itr > 0; itr--){ i2 now = pq.top(); pq.pop(); ans += now[0]; int id = now[1]; ptr[id]++; if (ptr[id] < k){ pq.push({-x[id][m - k + ptr[id]] - x[id][ptr[id]], id}); } } // add last tickets for (int i = 0, g1 = 0; i < n; i++){ int now = 0; for (int j = 0; j < ptr[i]; j++){ answer[i][j] = g1; g1++; if (g1 == k) g1 = 0; } for (int j = ptr[i], now = g1; j < k; j++){ answer[i][m - k + j] = now; now++; if (now == k) now = 0; } } allocate_tickets(answer); return ans; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:57:13: warning: unused variable 'now' [-Wunused-variable]
   57 |         int now = 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...