제출 #302697

#제출 시각아이디문제언어결과실행 시간메모리
302697leejseo카니발 티켓 (IOI20_tickets)C++17
100 / 100
1434 ms95408 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; int N, M, K; vector<vector<int>> ans; vector<pair<int, int>> A[1505], B[1505]; bool vis[1505]; int cmp(const vector<pair<int, int>> &x, const vector<pair<int, int>> &y){ return x.size() > y.size(); } priority_queue<pair<int, int>> pq; ll find_maximum(int k, vector<vector<int>> x) { N = x.size(); M= x[0].size(); K = k; for (int i = 0; i < N; i++) { vector<int> row(M); ans.push_back(row); } priority_queue<pair<int, pair<int, int>>> pq; ll res = 0; for (int i=0; i<N; i++) for (int j=0; j<M; j++) ans[i][j] = -1; for (int k=0; k<K; k++){ for (int i=0; i<N; i++){ res -= x[i][k]; ans[i][k] = -2; pq.push(make_pair(x[i][M-K+k]+x[i][k], make_pair(i, k))); } } int cnt = 0; while (cnt < N*K/2){ int a, b, c; tie(b, c) = pq.top().second; a = pq.top().first; pq.pop(); ++cnt; res += 1LL * a; ans[b][c] = -1; ans[b][M-K+c] = -3; } vector<vector<pair<int, int>>> I(N), J(N); for (int i=0; i<N; i++){ for (int j=0; j<M; j++){ if (ans[i][j] == -2) I[i].push_back(make_pair(i, j)); else if (ans[i][j] == -3) J[i].push_back(make_pair(i, j)); } } for (int k=0; k<K; k++){ sort(I.begin(), I.end(), cmp); memset(vis, 0, sizeof(vis)); for (int i=0; i<N/2; i++){ int a, b; tie(a, b) = I[i].back(); I[i].pop_back(); ans[a][b] = k; vis[a] = 1; } for (int i=0; i<N; i++){ int a, b; if (J[i].empty()) continue; tie(a, b) = J[i].back(); if (vis[a]) continue; J[i].pop_back(); ans[a][b] = k; vis[a] = 1; } } allocate_tickets(ans); return res; }
#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...