제출 #521239

#제출 시각아이디문제언어결과실행 시간메모리
521239Alex_tz307로봇 (IOI13_robots)C++17
100 / 100
1760 ms35744 KiB
#include <bits/stdc++.h> #include "robots.h" using namespace std; int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { sort(X, X + A); sort(Y, Y + B); vector<tuple<int, int, int>> sortedX(T), sortedY(T); for (int i = 0; i < T; ++i) { sortedX[i] = make_tuple(W[i], S[i], i); sortedY[i] = make_tuple(W[i], S[i], i); } sort(sortedX.begin(), sortedX.end()); sort(sortedY.begin(), sortedY.end(), [&](const tuple<int, int, int> &x, const tuple<int, int, int> &y) { return get<1>(x) < get<1>(y); }); auto check = [&](const int &m) -> int { vector<bool> taken(T); priority_queue<pair<int, int>> pq; int p = 0; for (int i = 0; i < A; ++i) { while (p < T && get<0>(sortedX[p]) < X[i]) { pq.emplace(get<1>(sortedX[p]), get<2>(sortedX[p])); p += 1; } int cnt = 0; while (!pq.empty() && cnt < m) { taken[pq.top().second] = true; cnt += 1; pq.pop(); } } p = 0; vector<int> q; for (int i = 0; i < B; ++i) { while (p < T && get<1>(sortedY[p]) < Y[i]) { if (!taken[get<2>(sortedY[p])]) { q.emplace_back(get<2>(sortedY[p])); } p += 1; } int cnt = 0; while (!q.empty() && cnt < m) { taken[q.back()] = true; cnt += 1; q.pop_back(); } } for (int i = 0; i < T; ++i) { if (!taken[i]) { return false; } } return true; }; int l = 1, r = T, ans = -1; while (l <= r) { int mid = (l + r) / 2; if (check(mid)) { ans = mid; r = mid - 1; } 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...