이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nl cout<<"\n"
#define s second
#define f first
#define all(x) x.begin(), x.end()
#define ca(v) for(auto i:v) cout<<i<<" ";
bool solve(int m, vector<int> &X, vector<int> &Y, vector<pair<int, int>> &T){
multiset<pair<int, int>> st;
for(int i:X) st.insert({i, m});
vector<pair<int, int>> P1;
vector<pair<int, int>> P2;
for(auto p:T) P1.push_back(p);
sort(all(P1));
while(P1.size()){
auto c = P1.back(); P1.pop_back();
auto it = st.upper_bound({c.s, m+1});
if(it != st.end()){
auto nxt = *it; st.erase(it);
nxt.s--;
if(nxt.s) st.insert(nxt);
}
else{
P2.push_back({c.s, c.f});
}
}
sort(all(P2));
st.clear();
for(int i:Y) st.insert({i, m});
while(P2.size()){
auto c = P2.back(); P2.pop_back();
auto it = st.upper_bound({c.s, m+1});
if(it != st.end()){
auto nxt = *it; st.erase(it);
nxt.s--;
if(nxt.s) st.insert(nxt);
}
else{
return false;
}
}
return true;
}
int putaway(int A, int B, int N, int x[], int y[], int w[], int s[]){
vector<int> X, Y, W, S;
for(int i=0; i<A; i++) X.push_back(x[i]);
for(int i=0; i<B; i++) Y.push_back(y[i]);
for(int i=0; i<N; i++) W.push_back(w[i]);
for(int i=0; i<N; i++) S.push_back(s[i]);
sort(all(X));
sort(all(Y));
int ans = N+1;
int l = 1;
int r = N;
vector<pair<int, int>> T;
for(int i=0; i<N; i++) T.push_back({S[i], W[i]});
while(l <= r){
int m = (l + r) / 2;
if(solve(m, X, Y, T)){
ans = m;
r = m-1;
}
else l = m+1;
}
if(ans == N+1) return -1;
return ans;
}
# | 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... |