제출 #1184790

#제출 시각아이디문제언어결과실행 시간메모리
1184790countless로봇 (IOI13_robots)C++20
0 / 100
1623 ms36308 KiB
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 998244353;
const ll INF = 1e18;
const ld EPS = 1e-12;

#define endl "\n"
#define sp <<" "<<
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define dbg(x) cout << #x << " = " << x << endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <typename Key, typename Value>
using hash_map = unordered_map<Key, Value, custom_hash>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// uniform_int_distribution<int>(a, b)(rng);
// shuffle(all(a), rng);

struct toy {
    ll weight, size, index;
};

bool compW(const toy &a, const toy &b) {
    if (a.weight == b.weight) return a.size < b.size;
    return a.weight < b.weight;
}

bool compS(const toy &a, const toy &b) {
    if (a.size == b.size) return a.weight < b.weight;
    return a.size < b.size;
}

int a, b, t;
vector<int> as, bs;
vector<toy> toysW, toysS;
vector<bool> vis;

bool helpe(int x) {
    int rem = t, ind;
    priority_queue<pair<int, int>> pq;

    ind = 0;
    REP(i, 0, a) {
        while (ind < t && (vis[toysW[ind].index] || toysW[ind].weight < as[i])) {
            if (!vis[toysW[ind].index])
                pq.push({toysW[ind].size, toysW[ind].index});
            ind++;
        }

        int cap = x;
        while (!pq.empty() && cap) {
            int ele = pq.top().second; pq.pop();
            cap--, rem--;
            vis[ele] = true;
        }
    }

    priority_queue<pair<int, int>>().swap(pq);
    ind = 0;
    REP(i, 0, b) {
        while (ind < t && (vis[toysS[ind].index] || toysS[ind].size < bs[i])) {
            if (!vis[toysS[ind].index])
                pq.push({toysS[ind].weight, toysS[ind].index});
            ind++;
        }

        int cap = x;
        while (!pq.empty() && cap) {
            int ele = pq.top().second; pq.pop();
            cap--, rem--;
            vis[ele] = true;
        }
    }

    return rem == 0;
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    a = A, b = B, t = T;
    as.resize(a), bs.resize(b), toysW.resize(t), toysS.resize(t);
    vis.assign(t, false);
    REP(i, 0, a) {
        as[i] = X[i];
    }

    if (a) sort(all(as));

    REP(i, 0, b) {
        bs[i] = Y[i];
    }

    if (b) sort(all(bs));

    REP(i, 0, t) {
        toysW[i] = toysS[i] = {W[i], S[i], i};
    }

    sort(all(toysW), compW);
    sort(all(toysS), compS);

    int l = 0, r = t+1;
    while (l < r) {
        int m = (l+r)/2;
        
        if (helpe(m)) {
            r = m;
        } else {
            l = m + 1;
        }

        vis.assign(t, false);
    }

    if (l) {
        return l;
    } else {
        return -1;
    }
}

// signed main() {
//     int a, b, t; cin >> a >> b >> t;
//     int x[a], y[b], w[t], s[t];
//     REP(i, 0, a) {
//         cin >> x[i];
//     }

//     REP(i, 0, b) {
//         cin >> y[i];
//     }

//     REP(i, 0, t) {
//         cin >> w[i] >> s[i];
//     }

//     cout << putaway(a, b, t, x, y, w, s) << endl;
// }
#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...