제출 #769438

#제출 시각아이디문제언어결과실행 시간메모리
769438boris_mihov로봇 (IOI13_robots)C++17
90 / 100
3007 ms34812 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::multiset <int> vals; std::priority_queue <int> pq; int check(int times, int X[], int Y[]) { vals.clear(); 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 (!pq.empty()) { vals.insert(pq.top()); pq.pop(); } while (ptr + 1 < n) { ptr++; vals.insert(sX[ptr]); } for (int curr = 0 ; curr < b && vals.size() ; ++curr) { for (int t = 0 ; t < times && vals.size() ; ++t) { if (Y[curr] < (*vals.begin())) break; auto it = std::prev(vals.upper_bound(Y[curr])); vals.erase(it); } } return vals.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; }

컴파일 시 표준 에러 (stderr) 메시지

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