제출 #362140

#제출 시각아이디문제언어결과실행 시간메모리
362140Sorting카니발 티켓 (IOI20_tickets)C++17
0 / 100
1 ms512 KiB
#include "tickets.h" #include <vector> #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1500 + 3; vector<vector<int>> x, answer; int n, m, k, idx[N]; array<int, 2> arr[N]; void clear(){ } ll solve(){ clear(); ll ans = 0; priority_queue<array<int, 2>> pq; int add = n * k / 2; for(int i = 0; i < n; ++i){ idx[i] = 0; pq.push({-x[i][0] - x[i][m - k], i}); } while(add--){ auto [score, i] = pq.top(); pq.pop(); idx[i]++; if(idx[i] < k) pq.push({-x[i][idx[i]] - x[i][m - k + idx[i]], i}); } for(int i = 0; i < n; ++i){ for(int j = 0; j < idx[i]; ++j){ answer[i][j] = 1; ans -= x[i][j]; } for(int j = idx[i] + m - k; j < m; ++j){ answer[i][j] = 2; ans += x[i][j]; } } set<array<int, 3>> s; for(int i = 0; i < k; ++i) s.insert({0, i, 0}); for(int i = 0; i < n; ++i){ vector<array<int, 3>> to_add; for(int j = 0; j < m; ++j){ if(answer[i][j] == -1) continue; array<int, 3> arr; if(answer[i][j] == 1) arr = *s.rbegin(); else arr = *s.begin(); auto [score, idx, cnt] = arr; s.erase(arr); answer[i][j] = idx; if(answer[i][j] == 1) score--; else score++; if(cnt != k - 1) to_add.push_back({score, idx, cnt + 1}); } for(auto arr: to_add) s.insert(arr); } return ans; } long long find_maximum(int _k, vector<vector<int>> _x) { k = _k; x = _x; n = x.size(); m = x[0].size(); answer.clear(); answer.resize(n, vector<int>(m, -1)); ll ans = solve(); allocate_tickets(answer); 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...