Submission #993549

#TimeUsernameProblemLanguageResultExecution timeMemory
993549Muaath_5Robots (IOI13_robots)C++17
28 / 100
3100 ms31964 KiB
#pragma GCC optimize("Ofast,O3,unroll-loops") #pragma GCC target("avx2,avx,sse3,sse4") #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[]) { if (A < B) { swap(A, B); swap(X, Y); swap(W, S); } sort(X, X+A); sort(Y, Y+B); vector<pair<int, int>> v; for (int i = 0; i < T; i++) v.push_back({W[i], S[i]}); sort(v.begin(), v.end()); for (int i = 0; i < T; i++) { W[i] = v[i].first, S[i] = v[i].second; if (A && B) if (W[i] >= X[A-1] && S[i] >= Y[B-1]) return -1; if (A && !B) if (W[i] >= X[A-1]) return -1; if (!A && B) if (S[i] >= Y[B-1]) return -1; } if (T == 2 && A+B == 2) { if (A==2) { if (*max_element(X, X+A) <= *max_element(W, W+T)) return -1; if (X[0] > W[0] && X[1] > W[1]) return 1; return 2; } if (B==2) { if (*max_element(Y, Y+B) <= *max_element(S, S+T)) return -1; if (Y[0] > S[0] && Y[1] > S[1]) return 1; return 2; } if ((X[0] > W[0] && Y[0] > S[1]) || (X[0] > W[1] && Y[0] > S[0])) return 1; if ((X[0] > W[0] && X[0] > W[1]) || (Y[0] > S[0] && Y[0] > S[1])) return 2; return -1; } if (B == 0) { multiset<int> s; for (int i = 0; i < T; i++) s.insert(W[i]); int sol = 0; while (s.size()) { for (int i = A-1; s.size() && i >= 0; i--) { auto it = s.lower_bound(X[i]); if (it == s.begin()) break; it--; s.erase(it); } sol++; } return sol; } int l = 1, r = T; while (l < r) { const int mid = (l+r+1)/2; bool ok = true; int idx = 0; priority_queue<int> pq; for (int i = 0; idx < T && i < A; i++) { while (idx < T && W[idx] < X[i]) { pq.push(S[idx]); idx++; } for (int j = 0; pq.size() && j < mid; j++) pq.pop(); } while (idx < T) { pq.push(S[idx]); idx++; } for (int i = B; pq.size() && i >= 0; i--) { for (int j = 0; pq.size() && j < mid; j++) { if (pq.top() < Y[i]) pq.pop(); } } if (pq.empty()) r = mid; else l = mid+1; } return l; }

Compilation message (stderr)

robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:71:14: warning: unused variable 'ok' [-Wunused-variable]
   71 |         bool ok = true;
      |              ^~
#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...