제출 #370990

#제출 시각아이디문제언어결과실행 시간메모리
370990shivensinha4로봇 (IOI13_robots)C++17
100 / 100
2553 ms12012 KiB
#include "bits/stdc++.h" #include"robots.h" #ifdef mlocal #include "grader.c" #endif using namespace std; #define for_(i, s, e) for (int i = s; i < (int) e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) typedef long long ll; typedef vector<int> vi; typedef array<int, 2> ii; //#define endl '\n' int a, b, t; vi wlim, slim, ct; vector<bool> done; vector<ii> toys; bool check(int box) { done.assign(t, false); ct.assign(b, box); set<ii> s; int rem = t; for_(i, 0, b) s.insert({slim[i], i}); for_(i, 0, t) { auto pt = s.lower_bound({toys[i][1], -1}); if (pt != s.end()) { done[i] = true; rem--; if (ct[(*pt)[1]] == 1) s.erase(pt); else ct[(*pt)[1]] -= 1; } } int pt = 0, ct; for_(i, 0, a) { ct = 0; while (pt < t and ct < box) { if (!done[pt] and toys[pt][0] <= wlim[i]) { ct++; rem--; done[pt] = true; } pt++; } } return !rem; } int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { a = A, b = B, t = T; wlim.reserve(A); slim.reserve(B); toys.reserve(T); for_(i, 0, a) { wlim.push_back(X[i]); wlim[i] -= 1; } for_(i, 0, b) { slim.push_back(Y[i]); slim[i] -= 1; } for_(i, 0, t) toys.push_back({W[i], S[i]}); sort(wlim.rbegin(), wlim.rend()); sort(slim.rbegin(), slim.rend()); sort(toys.rbegin(), toys.rend()); for_(i, 0, t) if ((a == 0 or toys[i][0] > wlim[0]) and (b == 0 or toys[i][1] > slim[0])) return -1; int l = 1, r = T+1, ans = r; while (l < r) { int mid = (l+r)/2; bool fin = check(mid); if (fin) { ans = r = mid; } else l = mid+1; } return ans; }
#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...