이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <queue>
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
int A, B, T, x[50005], y[50005], w[1000005], s[1000005], maxsz, maxwt;
pii byweight[1000005];
priority_queue<int> pq;
int check(int time) {
while (!pq.empty()) pq.pop();
// Let weak toys go first
int ptr = 0;
for (int i = 0; i < A; i++) {
while (ptr < T && byweight[ptr].fi < x[i]) {
pq.push(s[byweight[ptr].se]);
ptr++;
}
for (int j = 0; !pq.empty() && j < time; j++) {
pq.pop();
}
}
while (ptr < T) {
pq.push(s[byweight[ptr].se]);
ptr++;
}
for (int i = B-1; i >= 0; i--) {
if (!pq.empty() && pq.top() >= y[i]) {
return 0; // Game over
}
for (int j = 0; !pq.empty() && j < time; j++) {
pq.pop();
}
}
if (!pq.empty()) {
while (!pq.empty()) pq.pop();
return 0;
} else {
return 1;
}
}
int putaway(int a, int b, int t, int X[], int Y[], int W[], int S[]) {
A = a, B = b, T = t;
int cooked = 0;
for (int i = 0; i < A; i++) {
x[i] = X[i];
maxwt = max(maxwt, x[i]);
}
for (int i = 0; i < B; i++) {
y[i] = Y[i];
maxsz = max(maxsz, y[i]);
}
for (int i = 0; i < T; i++) {
w[i] = W[i], s[i] = S[i];
byweight[i] = { w[i], i };
if (s[i] >= maxsz && w[i] >= maxwt) return -1;
}
sort(x, x+A);
sort(y, y+B);
sort(byweight, byweight+T);
int lo = 0, hi = 1000005;
while (lo + 1 < hi) {
int mid = (lo + hi) / 2;
if (check(mid)) hi = mid;
else lo = mid;
}
return hi;
}
컴파일 시 표준 에러 (stderr) 메시지
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:52:6: warning: unused variable 'cooked' [-Wunused-variable]
int cooked = 0;
^~~~~~
# | 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... |