제출 #310207

#제출 시각아이디문제언어결과실행 시간메모리
310207amunduzbaev로봇 (IOI13_robots)C++14
90 / 100
2017 ms61304 KiB
#include "robots.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
multiset< pair<int, int> >wt, st, r;
int solve(){

    int ans=0;
    while(wt.size()>0&&st.size()>0){
        ans++;
        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,0});
                if(toy == wt.begin()) {
                    r.erase(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,0});
                if(toy == st.begin()){
                    r.erase(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";
        }

    }

    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;
}
/*

    */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...