Submission #769440

#TimeUsernameProblemLanguageResultExecution timeMemory
769440boris_mihovRobots (IOI13_robots)C++17
100 / 100
659 ms23972 KiB
#include "robots.h" #include <algorithm> #include <iostream> #include <numeric> #include <cassert> #include <vector> #include <bitset> #include <queue> #include <set> typedef long long llong; const int MAXN = 1000000 + 10; const int MAXAB = 50000 + 10; int n; int a, b; int wX[MAXN]; int sX[MAXN]; int permX[MAXN]; std::priority_queue <int> pq; int check(int times, int X[], int Y[]) { while (!pq.empty()) pq.pop(); int ptr = -1; int cntDestroyed = 0; for (int curr = 0 ; curr < a ; ++curr) { while (ptr + 1 < n && wX[ptr + 1] <= X[curr]) { ptr++; pq.push(sX[ptr]); } for (int t = 0 ; t < times && pq.size() ; ++t) { pq.pop(); } } while (ptr + 1 < n) { ptr++; pq.push(sX[ptr]); } for (int curr = b - 1 ; curr >= 0 && pq.size() ; --curr) { for (int t = 0 ; t < times && pq.size() ; ++t) { if (Y[curr] < pq.top()) return false; pq.pop(); } } return pq.empty(); } int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { a = A; b = B; n = T; std::iota(permX, permX + n, 0); std::sort(permX, permX + n, [&](const int &a, const int &b) { return W[a] < W[b]; }); for (int i = 0 ; i < n ; ++i) { wX[i] = W[permX[i]] + 1; sX[i] = S[permX[i]] + 1; } std::sort(X, X + a); std::sort(Y, Y + b); for (int i = 0 ; i < n ; ++i) { if (wX[i] > X[a - 1] && sX[i] > Y[b - 1]) { return -1; } } // std::cout << "byW\n"; // for (int i = 1 ; i <= n ; ++i) // { // std::cout << w[sortedX.perm[i]] << ' ' << s[sortedX.perm[i]] << '\n'; // } // std::cout << "byS\n"; // for (int i = 1 ; i <= n ; ++i) // { // std::cout << w[sortedY.perm[i]] << ' ' << s[sortedY.perm[i]] << '\n'; // } int pw = -1; while (!check(1 << pw + 1, X, Y)) pw++; int l = (pw == -1 ? 0 : (1 << pw)), r = (1 << pw + 1), mid; while (l < r - 1) { mid = (l + r) / 2; if (!check(mid, X, Y)) l = mid; else r = mid; } return r; }

Compilation message (stderr)

robots.cpp: In function 'int check(int, int*, int*)':
robots.cpp:26:9: warning: unused variable 'cntDestroyed' [-Wunused-variable]
   26 |     int cntDestroyed = 0;
      |         ^~~~~~~~~~~~
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:101:27: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
  101 |     while (!check(1 << pw + 1, X, Y)) pw++;
      |                        ~~~^~~
robots.cpp:103:54: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
  103 |     int l = (pw == -1 ? 0 : (1 << pw)), r = (1 << pw + 1), mid;
      |                                                   ~~~^~~
#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...