이 제출은 이전 버전의 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();
int m = x[0].size();
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
vector<int> row(m);
for (int j = 0; j < m; j++) {
row[j] = -1;
}
answer.push_back(row);
}
long long ans = 0ll;
int lo = 0;
int hi = 1e9;
int mid;
while(lo < hi){
mid = (lo + hi)/2;
int totcnt = 0;
for(int i = 0; i < n; i++){
int icnt = upper_bound(x[i].begin(),x[i].end(),mid) - x[i].begin();
totcnt += icnt;
}
if(totcnt >= n*m/2){
hi = mid;
}else{
lo = mid+1;
}
}
int totcnt = 0;
vector<int> negbar;
for(int i = 0; i < n; i++){
int icnt = upper_bound(x[i].begin(),x[i].end(),lo) - x[i].begin();
if(totcnt + icnt > n*m/2){
icnt = n*m/2 - totcnt;
}
negbar.push_back(icnt);
totcnt += icnt;
//cout << "i: " << i << ", negbar: " << icnt << ", totcnt: " << totcnt << endl;
}
for(int t = 0; t < k; t++){
vector<int> idxs;
for(int i = 0; i < n; i++) idxs.push_back(i);
sort(idxs.begin(), idxs.end(), [&negbar](int x, int y){
return negbar[x] < negbar[y];
});
vector<pair<int,int>> exact;
for(int i = 0; i < n/2; i++){
for(int j = m-1; j >= 0; j--){
if(answer[idxs[i]][j] == -1){
answer[idxs[i]][j] = t;
exact.emplace_back(x[idxs[i]][j], idxs[i]);
break;
}
}
}
for(int i = n/2; i < n; i++){
for(int j = 0; j < m; j++){
if(answer[idxs[i]][j] == -1){
answer[idxs[i]][j] = t;
exact.emplace_back(x[idxs[i]][j], idxs[i]);
break;
}
}
}
sort(exact.begin(), exact.end());
for(int i = 0; i < exact.size()/2; i++){
ans += exact[exact.size() - i - 1].first - exact[i].first;
negbar[exact[exact.size() - i - 1].second]--;
}
}
allocate_tickets(answer);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i = 0; i < exact.size()/2; i++){
| ~~^~~~~~~~~~~~~~~~
# | 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... |