이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include<bits/stdc++.h>
using namespace std;
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size(), m = x[0].size();
vector<vector<int>> answer(n, vector<int>(m, -1));
vector<deque<pair<int, int>>> t(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
t[i].push_back({x[i][j], j});
}
sort(t[i].begin(), t[i].end());
}
int ans = 0;
for (int c = 0; c < k; c++) {
vector<int> arr, vis(n, 0);
vector<tuple<int, int, int>> a;
for (int i = 0; i < n; i++) {
a.push_back({t[i].back().first, i, t[i].back().second});
if (t[i].size() > 1) {
a.push_back({t[i].front().first, i, t[i].front().second});
}
}
sort(a.begin(), a.end());
for (int ind = 0; ind < a.size(); ind++) {
auto [v, i, j] = a[ind];
if (arr.size() == n/2) {
break;
}
if (vis[i]) {
continue;
}
vis[i] = 1;
if (t[i].back().second == j) {
t[i].pop_back();
} else {
t[i].pop_front();
}
answer[i][j] = c;
arr.push_back(v);
}
reverse(a.begin(), a.end());
for (int ind = 0; ind < a.size(); ind++) {
auto [v, i, j] = a[ind];
if (vis[i]) {
continue;
}
vis[i] = 1;
if (t[i].back().second == j) {
t[i].pop_back();
} else {
t[i].pop_front();
}
answer[i][j] = c;
arr.push_back(v);
}
sort(arr.begin(), arr.end());
int med = arr[n/2];
for (int i = 0; i < n; i++) {
ans += abs(arr[i]-med);
}
}
allocate_tickets(answer);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:25:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int ind = 0; ind < a.size(); ind++) {
| ~~~~^~~~~~~~~~
tickets.cpp:27:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
27 | if (arr.size() == n/2) {
| ~~~~~~~~~~~^~~~~~
tickets.cpp:43:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int ind = 0; ind < a.size(); ind++) {
| ~~~~^~~~~~~~~~
# | 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... |