이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
const int inf=1e9+7;
multiset< pair<int, int> >wt, st, r;
int solve(){
int ans=0;
while(wt.size()>0&&st.size()>0){
ans++;
vector<pair<int,int>>del;
for(auto x:r){
if(!wt.size()&&!st.size()) break;
int robot=x.first;
int type=x.second;
//cout<<robot<<"\n";
if(type == 0)
{
auto toy = wt.upper_bound({robot,-inf});
if(toy == wt.begin()) {
del.push_back(x);
continue;
}
toy--;
int wtoy = (*toy).first;
int stoy = (*toy).second;
wt.erase( wt.find( {wtoy,stoy} ) );
st.erase( st.find( {stoy,wtoy} ) );
}
else
{
auto toy = st.upper_bound({robot,-inf});
if(toy == st.begin()){
del.push_back(x);
continue;
}
toy--;
int stoy = (*toy).first;
int wtoy = (*toy).second;
wt.erase( wt.find( {wtoy,stoy} ) );
st.erase( st.find( {stoy,wtoy} ) );
//cout<<"works\n";
}
//cout<<wt.size()<<"\n";
}
for(auto x:del){
r.erase(x);
}
}
return ans;
}
int putaway(int a, int b, int t, int a1[], int b1[], int w[], int s[]) {
sort(a1,a1+a);
sort(b1,b1+b);
int mxa=(a>0 ? a1[a-1]:0),mxb=(b>0 ? b1[b-1]:0);
for(int i=0;i<t;i++){
if(w[i]>=mxa&&s[i]>=mxb) return -1;
wt.insert({w[i],s[i]});
st.insert({s[i],w[i]});
}
for(int i=0;i<a;i++) r.insert({a1[i],0});
for(int i=0;i<b;i++) r.insert({b1[i],1});
int ans=solve();
return ans;
}
/*
2 0 2
20 10
10 7
10 13
*/
# | 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... |