이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define int long long
int find_maximum(signed k, std::vector<std::vector<signed>> x) {
int colors = x.size();
int ticketsPerColor = x[0].size();
int rounds = k;
if (ticketsPerColor == 1) {
int m = ticketsPerColor;
int n = colors;
int res = 0;
assert(m == 1);
vector<int> vals;
for (int i = 0; i<n; i++) {
vals.push_back(x[i][0]);
}
sort(vals.begin(), vals.end());
int med = vals[n/2];
for (int i: vals) res += abs(i-med);
vector<vector<signed>> cards(n, vector<signed>(m));
for (int i=0; i<n; i++) {
cards[i][0] = 0;
}
allocate_tickets(cards);
return res;
}
vector<array<int, 4>> cards(colors);
for (int i=0; i<colors; i++) {
cards[i][0] = (*max_element(x[i].begin(), x[i].end()))-(*min_element(x[i].begin(), x[i].end()));
cards[i][1] = min_element(x[i].begin(), x[i].end())-x[i].begin();
cards[i][2] = max_element(x[i].begin(), x[i].end())-x[i].begin();
cards[i][3] = i;
}
sort(cards.begin(), cards.end());
int res = 0;
vector<vector<signed>> allocation(colors, vector<signed>(ticketsPerColor, -1));
for (int i = 0; i<colors/2; i++) {
res += x[cards[i][3]][cards[i][2]];
allocation[cards[i][3]][cards[i][2]] = 0;
}
for (int i = colors/2; i<colors; i++) {
res -= x[cards[i][3]][cards[i][1]];
allocation[cards[i][3]][cards[i][1]] = 0;
}
allocate_tickets(allocation);
return abs(res);
}
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:14:6: warning: unused variable 'rounds' [-Wunused-variable]
14 | int rounds = k;
| ^~~~~~
# | 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... |