Submission #1201953

#TimeUsernameProblemLanguageResultExecution timeMemory
1201953dosts로봇 (IOI13_robots)C++20
0 / 100
71 ms4936 KiB
#include "robots.h"
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int> 
#define vi vector<int>
#define ff first
#define ss second
#define sp << " " << 
#define all(x) x.begin(),x.end()
using namespace std;

int32_t putaway(int32_t A, int32_t B, int32_t T, int32_t X[], int32_t Y[], int32_t W[], int32_t S[]) {
    //A tane X limiti
    //B tane Y limiti
    //X limitlerine göre robotları sırala
    //sürekli k tane alabildiğin <=y robotları al
    vi robots(A),robots2(B);
    iota(all(robots),0ll);
    iota(all(robots2),0ll);
    sort(all(robots),[&](int x,int y) {return X[robots[x]] < X[robots[y]];});
    sort(all(robots2),[&](int x,int y) {return Y[robots2[x]] < Y[robots2[y]];});
    vi toys(T);
    iota(all(toys),0ll);
    sort(all(toys),[&](int x,int y) {
        return W[x] < W[y];
    });
    priority_queue<int> pq;
    auto check = [&](int k) -> bool {
        int ptr = 0;
        while (!pq.empty()) pq.pop();
        for (int i = 0;i<A;i++) {
            while (ptr < T && W[toys[ptr]] < X[robots[i]]) {
                pq.push(S[toys[ptr]]);
                ptr++;
            }
            int rem = k;
            while (!pq.empty() && rem) {
                pq.pop();
                rem--;
            }
        }
        if (ptr < T) return false;
        else return pq.empty();
        while (ptr < T) {
            pq.push(S[toys[ptr]]);
            ptr++;
        }
        for (int i = B-1;i>=0;i--) {
            int rem = k;
            while (!pq.empty() && rem) {
                if (pq.top() >= Y[robots2[i]]) return false;
                pq.pop();
                rem--;
            }
        }
        return (pq.empty());
    };
    int l = 1;
    int r = T;
    while (l<=r) {
        int m = (l+r) >> 1;
        if (check(m)) r = m-1;
        else l = m+1;
    }
    if (l == T+1) return -1;
    return l;
}
#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...