이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "tickets.h"
using namespace std;
#define ll long long
ll find_maximum(int k, vector < vector < int > > x) {
#define f first
#define s second
int n = x.size();
int m = x[0].size();
vector < pair < int, int > > L(n);
stack < int > s[n], candidates[n];
priority_queue < pair < int, int > > q;
ll answer = 0;
for(int p = 0; p < n; ++p) {
L[p].s = p;
for(int i = m - 1; i >= m - k; --i) {
s[p].push(x[p][i]);
answer += x[p][i];
}
for(int i = m - 1; i >= 0; --i) {
candidates[p].push(x[p][i]);
}
if(!s[p].empty() && !candidates[p].empty()) {
q.push({-(s[p].top() + candidates[p].top()), p});
}
}
for(int rep = 0; rep < n * k / 2; ++rep) {
assert(q.size() > 0);
auto [x, y] = q.top();
q.pop();
s[y].pop();
candidates[y].pop();
answer += x;
++L[y].f;
if(!s[y].empty() && !candidates[y].empty()) {
q.push({-(s[y].top() + candidates[y].top()), y});
}
}
vector < vector < int > > less(n, vector < int >()), more(n, vector < int >());
for(int i = 0; i < n; ++i) {
for(int j = 0; j < L[i].f; ++j) {
less[i].push_back(j);
}
for(int j = m - (k - L[i].f); j < m; ++j) {
more[i].push_back(j);
}
}
vector < vector < int > > ans(n, vector < int > (m, -1));
for(int i = 0; i < k; ++i) {
sort(L.rbegin(), L.rend());
for(int j = 0; j < n / 2; ++j) {
assert(L[j].f > 0);
assert(less[L[j].s].size() > 0);
ans[L[j].second][less[L[j].s].back()] = i;
--L[j].f;
less[L[j].s].pop_back();
}
for(int j = n / 2; j < n; ++j) {
assert(more[L[j].s].size() > 0);
ans[L[j].second][more[L[j].s].back()] = i;
more[L[j].s].pop_back();
}
}
allocate_tickets(ans);
return answer;
}
// int main() {
// cout << find_maximum(1, {{5, 9}, {1, 4}, {3, 6}, {2, 7}}) << '\n';
// }
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:29:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
29 | auto [x, y] = q.top();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |