이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma once
#include <bits/stdc++.h>
#include "robots.h"
using namespace std;
template<typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
for (int i = 0; i < A; ++i) --X[i];
for (int i = 0; i < B; ++i) --Y[i];
sort(X, X+A);
sort(Y, Y+B);
vector<pair<int, int>> qs;
for (int i = 0; i < T; ++i) {
qs.push_back({W[i], S[i]});
if (W[i] > X[A-1] && S[i] > Y[B-1]) return -1;
}
sort(qs.begin(), qs.end());
//each robot takes at most k
auto check = [&] (int k) -> bool {
vector<int> to_y;
vector<vector<pair<int, int>>> to_x(A);
for (int i = 0; i < T; ++i) {
auto it = lower_bound(X, X+A, W[i]);
if (it == X+A) {
to_y.push_back(S[i]);
continue;
}
to_x[it-X].push_back({W[i], S[i]});
}
minheap<pair<int, int>> pq;
int cnt = 1;
for (int i = A-1; i >= 0; --i, ++cnt) {
for (auto [w, s] : to_x[i]) {
pq.push({s, w});
}
while (cnt * k < pq.size()) {
to_y.push_back(pq.top().first);
pq.pop();
}
}
sort(to_y.begin(), to_y.end());
vector<int> cntb(B, 0);
int ptr = 0;
for (int i = 0; i < to_y.size(); ++i) {
while (ptr < B && (cntb[ptr] == k || Y[ptr] < to_y[i])) ++ptr;
if (ptr == B) return false;
cntb[ptr]++;
}
return true;
};
int low = 0, high = T+1;
while (high - low > 1) {
int mid = (high + low) >> 1;
if (check(mid)) high = mid;
else low = mid;
}
return high;
}
컴파일 시 표준 에러 (stderr) 메시지
robots.cpp:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
robots.cpp: In lambda function:
robots.cpp:39:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | while (cnt * k < pq.size()) {
| ~~~~~~~~^~~~~~~~~~~
robots.cpp:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < to_y.size(); ++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... |