Submission #303331

#TimeUsernameProblemLanguageResultExecution timeMemory
303331myungwooCarnival Tickets (IOI20_tickets)C++17
100 / 100
1153 ms76488 KiB
#include <bits/stdc++.h> #include "tickets.h" using namespace std; #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define mt make_tuple typedef pair<int, int> pii; typedef tuple<int, int, int> tiii; typedef long long lld; lld find_maximum(int K, vector<vector<int>> A) { int N = A.size(); int M = A[0].size(); lld ans = 0; vector<vector<int>> answer(N, vector<int>(M, -1)); vector <tiii> order; for (int i=0;i<N;i++){ for (int k=0;k<K;k++) ans -= A[i][k]; for (int k=1;k<=K;k++) order.push_back(mt(A[i][M-k]+A[i][K-k], i, M-k)); } sort(order.begin(), order.end()); vector <int> cnt(N, 0), lpt(N, 0); for (int i=1;i<=K*N/2;i++){ auto [v, p, q] = order[order.size()-i]; ans += v; cnt[p]++; } for (int k=0;k<K;k++){ vector <pii> arr; for (int i=0;i<N;i++) arr.push_back({-cnt[i], i}); sort(arr.begin(), arr.end()); for (int i=0;i<N/2;i++){ int t = arr[i].second; assert(cnt[t] > 0); answer[t][M-cnt[t]] = k; cnt[t]--; } for (int i=N/2;i<N;i++){ int t = arr[i].second; answer[t][lpt[t]++] = k; } } 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...