이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
vector<int> used;
vector<pair<int, int>> toys;
multimap<int, int> wi, si;
vector<int> x, y;
bool can(int t){
multimap<int, int> sicur;
used.assign(toys.size(), false);
int j = 0;
int cnt = 0;
for (auto &i : wi) {
if(j >= x.size()) break;
if(i.first < x[j]){
sicur.insert({toys[i.second].second, i.second});
}
else{
while(i.first >= x[j]){
cnt = 0;
while(cnt < t && sicur.size()){
int k = (*--sicur.end()).second;
used[k] = true;
sicur.erase(--sicur.end());
cnt++;
}
j++;
if(j >= x.size()) {break;}
}
sicur.insert({toys[i.second].second, i.second});
}
}
for (int i = j; i < x.size(); i++) {
cnt = 0;
while(cnt < t && sicur.size()){
int k = (*--sicur.end()).second;
used[k] = true;
sicur.erase(--sicur.end());
cnt++;
}
}
vector<int> ss;
for (int i = 0; i < toys.size(); i++) {
if(!used[i]) ss.push_back(toys[i].second);
}
sort(all(ss), greater<int>());
j = 0;
for (int i = y.size() - 1; i >= 0; i--) {
cnt = 0;
while(cnt < t){
if(ss[j] < y[i]) {
j++;
if(j >= ss.size()) return 1;
cnt++;
}
else return 0;
}
}
return 0;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
for (int i = 0; i < T; i++) {
toys.push_back({W[i], S[i]});
wi.insert({W[i], i});
si.insert({S[i], i});
}
used.resize(T);
for (int i = 0; i < A; i++) x.push_back(X[i]);
for (int i = 0; i < B; i++) y.push_back(Y[i]);
sort(all(x));
sort(all(y));
int l = 0, r = T + 1, mid;
while(l < r){
mid = (l + r) / 2;
if(can(mid)) r = mid;
else l = mid + 1;
}
if(r == T + 1) return -1;
return r;
}
컴파일 시 표준 에러 (stderr) 메시지
robots.cpp: In function 'bool can(int)':
robots.cpp:20:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | if(j >= x.size()) break;
| ~~^~~~~~~~~~~
robots.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | if(j >= x.size()) {break;}
| ~~^~~~~~~~~~~
robots.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (int i = j; i < x.size(); i++) {
| ~~^~~~~~~~~~
robots.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0; i < toys.size(); i++) {
| ~~^~~~~~~~~~~~~
robots.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | if(j >= ss.size()) return 1;
| ~~^~~~~~~~~~~~
# | 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... |