제출 #151381

#제출 시각아이디문제언어결과실행 시간메모리
151381karma로봇 (IOI13_robots)C++14
76 / 100
3056 ms15504 KiB
#include <bits/stdc++.h>
#include "robots.h"
#pragma GCC optimization ("O3")
#define pb      emplace_back
#define mp      make_pair
#define fi      first
#define se      second

using namespace std;

const int N = int(1e6) + 1;
const int M = int(5e4) + 1;

int _W[N], _S[N];
struct LessW {
    bool operator()(const int& x, const int& y) {return _W[x] < _W[y];}
};
struct LessS {
    bool operator()(const int& x, const int& y) {return _S[x] < _S[y];}
};
priority_queue<int, vector<int>, LessW> pqw;
priority_queue<int, vector<int>, LessS> pqs;
vector<int> BaeW, BaeS;
bitset<N> del;

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{   // A -> W, B -> S
    sort(X, X + A); sort(Y, Y + B);
    for(int i = 0; i < T; ++i) {
        BaeW.pb(i), BaeS.pb(i);
        _W[i] = W[i], _S[i] = S[i];
    }
    sort(BaeW.begin(), BaeW.end(), [](const int& i, const int& j) {
            return _W[i] < _W[j];
        });
    sort(BaeS.begin(), BaeS.end(), [](const int& i, const int& j) {
            return _S[i] < _S[j];
        });
    int low = 1, high = T, mid, j, cur;
    while(low <= high) {
        mid = (low + high) >> 1;
        j = 0; del.reset(); while(pqs.size()) pqs.pop();
        for(int i = 0; i < A; ++i) {
           while(_W[BaeW[j]] < X[i] && j < T) pqs.push(BaeW[j]), ++j;
           cur = mid;
           while(cur > 0 && !pqs.empty()) --cur, del.set(pqs.top()), pqs.pop();
        }
        j = 0; while(pqw.size()) pqw.pop();
        for(int i = 0; i < B; ++i) {
            while(_S[BaeS[j]] < Y[i] && j < T) {
                if(!del.test(BaeS[j])) pqw.push(BaeS[j]);
                ++j;
            }
            cur = mid;
            while(cur > 0 && !pqw.empty()) --cur, del.set(pqw.top()), pqw.pop();
        }
        if(del.count() >= T) high = mid - 1;
        else low = mid + 1;
    }
    return low <= T? low: -1;
}
//
//int A, B, T, X[M], Y[M], W[N], S[N];
//
//int main()
//{
//    ios_base::sync_with_stdio(0);
//    cin.tie(0), cout.tie(0);
//    if(fopen("test.inp", "r")) {
//        freopen("test.inp", "r", stdin);
//        freopen("test.out", "w", stdout);
//    }
//    cin >> A >> B >> T;
//    for(int i = 0; i < A; ++i) cin >> X[i];
//    for(int i = 0; i < B; ++i) cin >> Y[i];
//    for(int i = 0; i < T; ++i) cin >> W[i] >> S[i];
//    cout << putaway(A, B, T, X, Y, W, S);
//}

컴파일 시 표준 에러 (stderr) 메시지

robots.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:57:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(del.count() >= T) high = mid - 1;
            ~~~~~~~~~~~~^~~~
#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...