Submission #592907

#TimeUsernameProblemLanguageResultExecution timeMemory
592907AQTCarnival Tickets (IOI20_tickets)C++14
0 / 100
1 ms340 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; /* void allocate_tickets(vector<vector<int>> arr) { for(auto v : arr) { for(auto n : v) { cout << n << " "; } cout << "\n"; } } */ long long find_maximum(int K, vector<vector<int>> arr) { int N = arr.size(); int M = arr[0].size(); int G = M - K; long long ans = 0; vector<vector<int>> ret; vector<vector<int>> typ; ret.resize(N); typ.resize(N); priority_queue<pair<int, pair<int, int>>> pq; for(int i = 0; i < N; i++) { ret[i].resize(M, -1); typ[i].resize(M); for(int j = M - 1; j >= M - K; j--) { ans += arr[i][j]; pq.push(make_pair(-arr[i][j] - arr[i][j-G], make_pair(i, j))); typ[i][j] = 1; } } int tot = N * K / 2; while(tot--) { auto p = pq.top(); ans += p.first; typ[p.second.first][p.second.second] = 0; typ[p.second.first][p.second.second-G] = -1; pq.pop(); } vector<pair<int, int>> cnt(N); vector<int> tkn(N); for(int i = 0; i < N; i++) { int c = 0; for(int j = 0; j < M; j++) { if(typ[i][j] == 1) { c++; } } cnt.emplace_back(c, i); } for(int k = 0; k < K; k++) { sort(cnt.begin(), cnt.end()); for(int n = 0; n < N / 2; n++) { auto p = cnt[n]; ret[p.second][k - tkn[p.second]] = k; } for(int n = N/2; n < N; n++) { pair<int,int>& p = cnt[n]; tkn[p.second]++; ret[p.second][M-1-tkn[p.second]] = k; tkn[p.second]++; p.first--; } } allocate_tickets(ret); return ans; }
#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...