제출 #604201

#제출 시각아이디문제언어결과실행 시간메모리
604201skittles1412카니발 티켓 (IOI20_tickets)C++17
27 / 100
518 ms51916 KiB
#include "bits/extc++.h" using namespace std; template <typename T> void dbgh(const T& t) { cerr << t << endl; } template <typename T, typename... U> void dbgh(const T& t, const U&... u) { cerr << t << " | "; dbgh(u...); } #ifdef DEBUG #define dbg(...) \ cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \ dbgh(__VA_ARGS__); #else #define dbg(...) #define cerr \ if (false) \ cerr #endif using ll = long long; #define endl "\n" #define long int64_t #define sz(x) int((x).size()) void allocate_tickets(std::vector<std::vector<int>> _x); ll find_maximum(int k, vector<vector<int>> arr) { int n = sz(arr), m = sz(arr[0]); long ans = 0; for (auto& a : arr) { assert(is_sorted(begin(a), end(a))); ans -= accumulate(a.begin(), a.begin() + k, long(0)); } int cnt[n] {}; priority_queue<pair<int, int>> pq; auto upd = [&](int i) -> void { if (cnt[i] >= k) { return; } pq.emplace(arr[i][k - cnt[i] - 1] + arr[i][m - cnt[i] - 1], i); }; for (int i = 0; i < n; i++) { upd(i); } for (int i = 0; i < n * k / 2; i++) { auto [d, j] = pq.top(); pq.pop(); ans += d; cnt[j]++; upd(j); } vector<vector<int>> qans(n, vector<int>(m, -1)); vector<int> inds[n][2]; for (int i = 0; i < n; i++) { for (int j = 0; j < k - cnt[i]; j++) { inds[i][0].push_back(j); } for (int j = 0; j < cnt[i]; j++) { inds[i][1].push_back(m - j - 1); } } for (int i = 0; i < k; i++) { int cur = 0; for (int j = 0; j < n; j++) { int ci; if (cur < n / 2 && sz(inds[j][0])) { cur++; ci = 0; } else { ci = 1; } qans[j][inds[j][ci].back()] = i; inds[j][ci].pop_back(); } } allocate_tickets(qans); 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...