Submission #1064661

#TimeUsernameProblemLanguageResultExecution timeMemory
1064661ArthuroWich로봇 (IOI13_robots)C++17
100 / 100
1552 ms32760 KiB
#include "robots.h"
#include<bits/stdc++.h>
using namespace std;
int n, m, t;
vector<int> weak, small;
vector<tuple<int, int, int>> toy;
bool check(int x) {
    vector<int> vis(t, 0);
    int ind = 0;
    priority_queue<pair<int, int>> pq;
    for (int i : weak) {
        while(ind < t) {
            auto [w, s, j] = toy[ind];
            if (w < i) {
                pq.push({s, j});
                ind++;
            } else {
                break;
            }
        }
        int co = x;
        while(!pq.empty() && co) {
            auto [_, j] = pq.top();
            pq.pop();
            vis[j] = 1;
            co--;
        }
    }
    while(ind < t) {
        auto [w, s, j] = toy[ind];
        pq.push({s, j});
        ind++;
    }
    for (int i : small) {
        int co = x;
        while(!pq.empty() && co) {
            auto [s, j] = pq.top();
            pq.pop();
            if (s < i) {
                vis[j] = 1;
                co--;
            } else {
                return 0;
            }
        }
    }
    for (int i = 0; i < t; i++) {
        if (vis[i]) {
            continue;
        }
        return 0;
    }
    return 1;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    n = A, m = B, t = T;
    for (int i = 0; i < t; i++) {
        toy.push_back({W[i], S[i], i});
    }
    for (int i = 0; i < n; i++) {
        weak.push_back(X[i]);
    }
    for (int i = 0; i < m; i++) {
        small.push_back(Y[i]);
    }
    int l = 1, r = T;
    sort(toy.begin(), toy.end());
    sort(weak.begin(), weak.end());
    sort(small.rbegin(), small.rend());
    while(l < r) {
        int m = (l+r)/2;
        if (check(m)) {
            r = m;
        } else {
            l = m+1;
        }
    }
    if (check(l)) {
        return l;
    } else {
        return -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...