제출 #168430

#제출 시각아이디문제언어결과실행 시간메모리
168430tri로봇 (IOI13_robots)C++14
90 / 100
3063 ms50224 KiB
#include <bits/stdc++.h>
#include "robots.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back
#define f first
#define s second

namespace debug {
    const int DEBUG = true;

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x);

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x);

    template<class T>
    void pr(const vector<T> &x);

    template<class T>
    void pr(const set<T> &x);

    template<class T1, class T2>
    void pr(const map<T1, T2> &x);

    template<class T>
    void pr(const T &x) { if (DEBUG) cout << x; }

    template<class T, class... Ts>
    void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }

    template<class T>
    void prIn(const T &x) {
        pr("{");
        bool fst = 1;
        for (auto &a : x) {
            pr(fst ? "" : ", ", a), fst = 0;
        }
        pr("}");
    }

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x) { prIn(x); }

    template<class T>
    void pr(const vector<T> &x) { prIn(x); }

    template<class T>
    void pr(const set<T> &x) { prIn(x); }

    template<class T1, class T2>
    void pr(const map<T1, T2> &x) { prIn(x); }

    void ps() { pr("\n"), cout << flush; }

    template<class Arg, class... Args>
    void ps(const Arg &first, const Args &... rest) {
        pr(first, " ");
        ps(rest...);
    }
}
using namespace debug;

int N, nA, nB;

vector<pi> reqs;

vi aL, bL;

bool pos(int T) {
//    ps(T);

    vi a;
    multiset<int> b;

    for (int i = aL.size() - 1; i >= 0; i--) {
        for (int j = 0; j < T && a.size() < N; j++) {
            a.pb(aL[i]);
        }
    }

    for (int i = bL.size() - 1; i >= 0; i--) {
        for (int j = 0; j < T && b.size() < N; j++) {
            b.insert(bL[i]);
        }
    }

    priority_queue<int, vi, greater<int>> swap;

    int nA = 0;
    for (int i = N - 1; i >= 0; i--) {

        if (nA < a.size() && a[nA] >= reqs[i].f) {
            swap.push(reqs[i].s);
            nA++;
        } else {
            swap.push(reqs[i].s);
            int needB = swap.top();
            swap.pop();

            auto it = b.lower_bound(needB);
            if (it == b.end()) {
                return false;
            }
            b.erase(it);
        }
    }
    return true;
}

int binSearch() {
    int low = 1;
    int hi = N + 1;

    while (low != hi) {
        int mid = (low + hi) / 2;
        if (pos(mid)) {
            hi = mid;
        } else {
            low = mid + 1;
        }
    }
    return low;
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    N = T, nA = A, nB = B;

    for (int i = 0; i < nA; i++) {
        aL.pb(X[i] - 1);
    }
    for (int i = 0; i < nB; i++) {
        bL.pb(Y[i] - 1);
    }

    for (int i = 0; i < N; i++) {
        reqs.pb({W[i], S[i]});
    }

    sort(aL.begin(), aL.end());
    sort(bL.begin(), bL.end());
    sort(reqs.begin(), reqs.end());
//
//    ps(aL);
//    ps(bL);
//    ps(reqs);

    int time = binSearch();
    if (time == N + 1) {
        return -1;
    }
    return time;
}

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

robots.cpp: In function 'bool pos(int)':
robots.cpp:91:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < T && a.size() < N; j++) {
                                  ~~~~~~~~~^~~
robots.cpp:97:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < T && b.size() < N; j++) {
                                  ~~~~~~~~~^~~
robots.cpp:107:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (nA < a.size() && a[nA] >= reqs[i].f) {
             ~~~^~~~~~~~~~
#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...