제출 #370988

#제출 시각아이디문제언어결과실행 시간메모리
370988shivensinha4로봇 (IOI13_robots)C++17
28 / 100
268 ms9068 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' // Ask for sum 1 -> n for full (one based indexing) class BIT { private: vector<ll> tree; int n = 1e6; int LSOne(int x) { return x&(-x); } public: void build(int x) { n = x; tree.resize(n+1); } ll sum(int a) { ll sum = 0; for (; a > 0; a -= LSOne(a)) sum += tree[a]; return sum; } ll sum(int a, int b) { return sum(b) - (a == 1 ? 0 : sum(a-1)); } void update(int p, ll v) { for (; p < n+1; p += LSOne(p)) tree[p] += v; } }; int a, b, t; vi wlim, slim; vector<ii> toys; BIT tree; bool check(ll box) { vector<bool> done(t); int pt = 0; for_(i, 0, b) { int ct = 0; while (pt < t and ct < box) { if (toys[pt][1] <= slim[i]) { ct++; done[pt] = true; } pt++; } } pt = 0; for_(i, 0, a) { int ct = 0; while (pt < t and ct < box) { if (!done[pt] and toys[pt][0] <= wlim[i]) { ct++; done[pt] = true; } pt++; } } for_(i, 0, t) if (!done[i]) return false; return true; } 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.begin(), wlim.end(), greater<>()); sort(slim.begin(), slim.end(), greater<>()); sort(toys.begin(), toys.end(), greater<>()); for_(i, 0, t) if ((a == 0 or toys[i][0] > wlim[0]) and (b == 0 or toys[i][1] > slim[0])) return -1; tree.build(max(a, b)); int l = 0, 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...