이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<long long, long long> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
#define pb push_back
#define fi first
#define se second
#define whole(v) v.begin(), v.end()
#define rwhole(v) v.rbegin(), v.rend()
#define inf INT_MAX/2
#define fro front
int A, B, T;
int x[1000010];
int y[1000010];
int w[1000010];
int s[1000010];
vector<ii> z;
bool f(int n){
int j = 0;
int i = 0;
vector<int> ne;
priority_queue<int, vector<int>, greater<int>> q;
for(j; j <= A; ++j){
while(i < z.size() && z[i].fi >= x[j]){
q.push(z[i].se);
++i;
}
while(q.size() > j * n){
ne.pb(q.top());
q.pop();
}
}
sort(whole(ne));
i = 0;
j = 0;
int cnt = ne.size();
if(ne.size() <= 0){
return 1;
}
for(j; j < B; ++j){
int cn = 0;
while(ne[i] < y[j]){
if(cn == n){
break;
}
cn++;
cnt--;
++i;
if(i >= ne.size()){
break;
}
}
if(i >= ne.size()){
break;
}
}
if(cnt > 0){
return 0;
}else{
return 1;
}
}
int putaway(int a, int b, int t, int X[], int Y[], int W[], int S[]){
//memset(x, 0, sizeof x);
for(int i = 0; i < a; ++i){
x[i] = X[i];
}
for(int i = 0; i < b; ++i){
y[i] = Y[i];
}
for(int i = 0; i < t; ++i){
w[i] = W[i];
}
for(int i = 0; i < t; ++i){
s[i] = S[i];
}
sort(x, x+a);
sort(y, y+b);
reverse(x, x+a);
A = a;
B = b;
T = t;
for(int i = 0; i < t; ++i){
z.pb(ii(w[i], s[i]));
}
sort(rwhole(z));
int lo = 0;
int hi = t + 2;
while(hi - lo > 1){
int mi = lo + (hi - lo) / 2;
if(f(mi)){
hi = mi;
}else{
lo = mi;
}
}
if(hi > t){
return -1;
}
return hi;
}
/*int main(){
int a = 3;
int b = 2;
int t = 10;
int X[] = {6, 2, 9};
int Y[] = {4, 7};
int W[] = {4, 8, 2, 7, 1, 5, 3, 8, 7, 10};
int S[] = {6, 5, 3, 9, 8, 1, 3, 7, 6, 5};
cout << putaway(a, b, t, X, Y, W, S) << endl;
}*/
컴파일 시 표준 에러 (stderr) 메시지
robots.cpp: In function 'bool f(int)':
robots.cpp:33:9: warning: statement has no effect [-Wunused-value]
33 | for(j; j <= A; ++j){
| ^
robots.cpp:34:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | while(i < z.size() && z[i].fi >= x[j]){
| ~~^~~~~~~~~~
robots.cpp:38:24: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
38 | while(q.size() > j * n){
| ~~~~~~~~~^~~~~~~
robots.cpp:50:9: warning: statement has no effect [-Wunused-value]
50 | for(j; j < B; ++j){
| ^
robots.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | if(i >= ne.size()){
| ~~^~~~~~~~~~~~
robots.cpp:63:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | if(i >= ne.size()){
| ~~^~~~~~~~~~~~
# | 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... |