이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "robots.h"
using namespace std;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
sort(X, X + A);
sort(Y, Y + B);
vector<pair<int,int>> omg;
for(int i = 0; i < T; i++) {
omg.push_back({W[i], S[i]});
}
sort(omg.begin(), omg.end());
int l = 1, r = 1e6, ans = - 1;
while(l <= r) {
int mid = (l + r) / 2;
int pok = A - 1;
int R = 0;
int pok1 = B - 1;
int ok = 0;
int R1 = 0;
multiset<pair<int,int>> ms;
for(int i = 0; i < B; i++) {
ms.insert({Y[i], 0});
}
for(int i = omg.size() - 1; i >= 0; i--) {
//cout << i << ":::\n";
//cout << "\n";
if(pok < 0 && !ms.size()) {
ok = 1;
//cout << "NEMOGU NIJEDAN\n";
break;
}
if(pok < 0) {
auto it = ms.upper_bound({omg[i].second, -1});
if(it == ms.end()) {
ok = 1;
//cout << "MORAO SAM IZ MS A NISAM IMAO STA DA UZMEM\n";
break;
}
int e1 = (*it).first;
int e2 = (*it).second;
e2 += 1;
ms.erase(it);
if(e2 >= mid) {
//cout << "obrisao sam i nisam ubacio natrag " << e1 << " " << e2 << "\n";
}
else {
ms.insert({e1, e2});
//cout << "ubacio sam1:" << e1 << " " << e2 << "\n";
}
continue;
}
if(!ms.size()) {
if(X[pok] <= omg[i].first) {
ok = 1;
//cout << "NISAM MOGAO IZ MS A TAKODJE NI IZ X\n";
break;
}
R += 1;
if(R >= mid) {
R = 0;
pok -= 1;
}
continue;
}
if(X[pok] <= omg[i].first) {
//! moram optimalno iz ms da uzmem i da azuriram
auto it = ms.upper_bound({omg[i].second, -1});
if(it == ms.end()) {
ok = 1;
//cout << "NEMOGU IZ X A NEMOGU NI IZ MS69\n";
break;
}
int e1 = (*it).first;
int e2 = (*it).second;
e2 += 1;
ms.erase(it);
if(e2 >= mid) {
//cout << "obrisao sam i nisam ubacio natrag " << e1 << " " << e2 << "\n";
}
else {
ms.insert({e1, e2});
//cout << "ubacio sam2:" << e1 << " " << e2 << "\n";
}
continue;
}
auto IT = ms.upper_bound({omg[i].second, -1});
int nemamkogaizms = 0;
if(IT == ms.end()) {
nemamkogaizms = 1;
}
if(nemamkogaizms) {
if(X[pok] <= omg[i].first) {
ok = 1;
//cout << "NEMOGU NI IZ MS NI IZ X\n";
break;
}
R += 1;
if(R >= mid) {
R = 0;
pok -= 1;
}
continue;
}
// mogu oba gledam manji R
auto it = ms.upper_bound({omg[i].second, -1});
int e1 = (*it).first;
int e2 = (*it).second;
ms.erase(it);
if(e2 <= R) {
e2 += 1;
if(e2 >= mid) {
//cout << "obrisao sam i nisam ubacio natrag " << e1 << " " << e2 << "\n";
}
else {
ms.insert({e1, e2});
//cout << "ubacio sam3:" << e1 << " " << e2 << "\n";
}
}
else {
ms.insert({e1, e2});
R += 1;
if(R >= mid) {
R = 0;
pok -= 1;
}
}
}
ok ^= 1;
if(ok) {
r = mid - 1;
ans = mid;
}
else {
l = mid + 1;
}
}
return ans;
}
/*
int main() {
int A = 3;
int B = 2;
int T = 10;
int X[3] = {6, 2, 9};
int Y[2] = {4, 7};
int W[10] = {4, 8, 2, 7, 1, 5, 3, 8, 7, 10};
int S[10] = {6, 5, 3, 9, 8, 1, 3, 7, 6, 5};
cout << putaway(A, B, T, X, Y, W, S);
int A = 2;
int B = 1;
int T = 3;
int X[2] = {2, 5};
int Y[1] = {2};
int W[3] = {3, 5, 2};
int S[3] = {1, 3, 2};
cout << putaway(A, B, T, X, Y, W, S);
}*/
컴파일 시 표준 에러 (stderr) 메시지
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:20:13: warning: unused variable 'pok1' [-Wunused-variable]
20 | int pok1 = B - 1;
| ^~~~
robots.cpp:22:13: warning: unused variable 'R1' [-Wunused-variable]
22 | int R1 = 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... |