이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
#define FORD(i, j, k, l) for(int i = (j); i >= (k); i -= (l))
#define REP(i, n) FOR(i, 0, n, 1)
#define REPD(i, n) FORD(i, n, 0, 1)
typedef long long ll;
#define pb push_back
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<array<int, 3>> tm;
REP(i, n){
REP(j, k){
tm.pb({x[i][j], i, j});
}
}
sort(tm.begin(), tm.end());
vector<int> upper(n);
vector<vector<array<int, 2>>> rows(n);
ll sum_up = 0;
ll sum_down = 0;
REP(i, tm.size() / 2){
upper[tm[i][1]] = tm[i][2] + 1;
rows[tm[i][1]].pb({tm[i][0], tm[i][2]});
sum_down += tm[i][0];
}
REP(i, n){
REP(j, k - upper[i]){
rows[i].pb({x[i][m - 1 - j], m - 1 - j});
sum_up += x[i][m - 1 - j];
}
}
vector<int> cnts = upper; // cnt smaller available
vector<vector<int>> answer(n, vector<int>(m, -1));
vector<int> sorted(n);
iota(sorted.begin(), sorted.end(), 0);
auto cmp = [&](int f, int s){
return cnts[f] > cnts[s];
};
REP(i, k){
sort(sorted.begin(), sorted.end(), cmp);
REP(j, n / 2){
cnts[sorted[j]]--;
int row = sorted[j]; int col = rows[row][cnts[row]][1];
answer[row][col] = i;
}
FOR(j, n / 2, n, 1){
int row = sorted[j];
int smaller_taken = upper[row] - cnts[row];
int col = k - 1 - i + smaller_taken;
col = rows[row][col][1];
answer[row][col] = i;
}
}
allocate_tickets(answer);
return sum_up - sum_down;
}
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:4:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
| ^
tickets.cpp:6:19: note: in expansion of macro 'FOR'
6 | #define REP(i, n) FOR(i, 0, n, 1)
| ^~~
tickets.cpp:24:5: note: in expansion of macro 'REP'
24 | REP(i, tm.size() / 2){
| ^~~
# | 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... |