Submission #740243

#TimeUsernameProblemLanguageResultExecution timeMemory
740243Dan4LifeRobots (IOI13_robots)C++17
100 / 100
1538 ms13040 KiB
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
const int mxN = (int)5e4+10;
int n, m, t, x[mxN], y[mxN];

struct Toy{ int w, s; };
vector<Toy> toy;

bool chk(int tim){
    priority_queue<int> pq;
    while(sz(pq))pq.pop(); int j=0;
    for(int i = 0; i < n; i++){
        while(j<t and toy[j].w<x[i])
            pq.push(toy[j++].s);
        int xd = tim;
        while(xd-- and sz(pq)) pq.pop();
    }
    while(j<t) pq.push(toy[j++].s);
    for(int i = m-1; i >= 0; i--){
        int xd = tim;
        while(xd-- and sz(pq)){
            if(pq.top()>=y[i]) return 0;
            pq.pop();
        }
    }
    return !sz(pq);
}

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 < n; i++) x[i] = X[i];
    for(int i = 0; i < m; i++) y[i] = Y[i];
    for(int i = 0; i < t; i++) toy.pb({W[i],S[i]});
    sort(x,x+n), sort(y,y+m);
    sort(begin(toy),end(toy),[&](Toy a, Toy b){return a.w<b.w;});
    int l = 0, r = t+1;
    while(l<r){
        int mid = (l+r)/2;
        if(chk(mid)) r=mid;
        else l=mid+1;
    }
    return l==t+1?-1:l;
}

Compilation message (stderr)

robots.cpp: In function 'bool chk(int)':
robots.cpp:14:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   14 |     while(sz(pq))pq.pop(); int j=0;
      |     ^~~~~
robots.cpp:14:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   14 |     while(sz(pq))pq.pop(); int j=0;
      |                            ^~~
#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...