Submission #272198

#TimeUsernameProblemLanguageResultExecution timeMemory
272198BertedRobots (IOI13_robots)C++14
100 / 100
2540 ms18172 KiB
#include "robots.h" #include <algorithm> #include <queue> #include <iostream> #include <bitset> #define pii pair<int, int> #define fst first #define snd second #define ppi pair<pii, int> using namespace std; const int INF = 1e9; int N, M, K, a[50001], b[50001]; pii ar[1000001], srt[1000001]; bitset<1000001> used; priority_queue<pii> pq; inline int eval(int k) { used.reset(); int j = 0; for (int i = 0; i < M; i++) { for (; j < K && srt[j].fst < b[i]; j++) {pq.push({ar[srt[j].snd].fst, srt[j].snd});} for (int j = 0; j < k && pq.size(); j++) {used[pq.top().snd] = 1; pq.pop();} } while (pq.size()) pq.pop(); j = N - 1; for (int i = K - 1; i >= 0; i--) { if (!used[i]) { for (; j >= 0 && a[j] > ar[i].fst; j--) {pq.push({0, j});} if (pq.size()) {int u = pq.top().fst, v = pq.top().snd; pq.pop(); pq.push({u - 1, v});} else {return INF;} } } int ret = 0; while (pq.size()) {ret = -pq.top().fst; pq.pop();} return ret; } int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { N = A; M = B; K = T; for (int i = 0; i < N; i++) {a[i] = X[i];} for (int i = 0; i < M; i++) {b[i] = Y[i];} for (int i = 0; i < K; i++) {ar[i] = {W[i], S[i]};} sort(a, a + N); sort(b, b + M); sort(ar, ar + K); for (int i = 0; i < K; i++) {srt[i] = {ar[i].snd, i};} sort(srt, srt + K); int L = 0, R = T + 1; while (L < R) { int M = L + R >> 1; if (eval(M) > M) L = M + 1; else R = M; } int res = INF; for (int i = max(0, L - 1); i <= L; i++) { res = min(res, max(eval(i), i)); } if (res == INF) return -1; else return res; }

Compilation message (stderr)

robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:59:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |   int M = L + R >> 1;
      |           ~~^~~
#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...