Submission #587472

#TimeUsernameProblemLanguageResultExecution timeMemory
587472usuyusRobots (IOI13_robots)C++14
100 / 100
660 ms25120 KiB
#include "robots.h" #include <bits/stdc++.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<vector<int>> pts(B+1); vector<int> init_up(A+1), init_right(B+1); for (int i=0; i<T; i++){ int x = upper_bound(X, X+A, W[i]) - X; int y = upper_bound(Y, Y+B, S[i]) - Y; if (x == A && y == B) return -1; else if (x == A) ++init_right[y]; else if (y == B) ++init_up[x]; else pts[y].push_back(x); } for (auto &v : pts) sort(v.begin(), v.end()); auto try_answer = [&] (int k) { auto up = init_up, right = init_right; priority_queue<int> pq; for (int i=0; i<B; i++) { for (int j : pts[i]) pq.push(j); while (!pq.empty() && right[i] < k) { int j = pq.top(); pq.pop(); ++right[i]; } if (right[i] > k) { right[i+1] += right[i] - k; right[i] = k; } } while (!pq.empty()) { int j = pq.top(); pq.pop(); ++up[j]; } for (int j=0; j<A; j++) { if (up[j] > k) { up[j+1] += up[j] - k; up[j] = k; } } // cout << k << " -> " << (up[A] == 0 && right[B] == 0) << endl; return up[A] == 0 && right[B] == 0; }; int l = 0, r = T; while ((r-l) > 1) { int m = (l+r) / 2; if (try_answer(m)) r = m; else l = m; } return r; }

Compilation message (stderr)

robots.cpp: In lambda function:
robots.cpp:33:21: warning: unused variable 'j' [-Wunused-variable]
   33 |                 int j = pq.top(); pq.pop();
      |                     ^
#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...