Submission #781878

#TimeUsernameProblemLanguageResultExecution timeMemory
781878caganyanmazRobots (IOI13_robots)C++17
76 / 100
3043 ms42616 KiB
#include <bits/stdc++.h> #include "robots.h" //#define DEBUGGING using namespace std; constexpr static int DEBUG_PRINT_SIZE = 10; void __print(int i) { cerr << i; } void __print(const char* c) { cerr << c; } void __print(int* i) { cerr << "{"; for (int j = 0; j < DEBUG_PRINT_SIZE; j++) { cerr << (j ? ", " : ""); __print(i[j]); } cerr << "}"; } template<typename T> void __print(T& t) { cerr << "{"; int f = 0; for (auto& i : t) { cerr << (f++ ? ", " : ""); __print(i); } cerr << "}"; } void _print() { cerr << "]\n"; } template<typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifdef DEBUGGING #define debug(x...) cerr << "[" << (#x) << "] = ["; _print(x) #else #define debug(x...) #endif bool is_possible(int a, int b, int t, int x[], int y[], const vector<array<int, 2>>& v, int k); int ceil_div(int a, int b); int putaway(int a, int b, int t, int x[], int y[], int ww[], int ss[]) { vector<array<int, 2>> v(t); sort(x, x + a); sort(y, y + b); for (int i = 0; i < t; i++) v[i] = {ww[i], ss[i]}; sort(v.begin(), v.end()); debug(x, y, v); int l = 0, r = t+1; while (r - l > 1) { int m = l+r>>1; if (is_possible(a, b, t, x, y, v, m)) { r = m; } else { l = m; } } if (r == t+1) return -1; return r; } constexpr static int MXSIZE = 50000; int ycounts[MXSIZE]; bool insert_to_ycounts(int y[], int b, int val); bool is_possible(int a, int b, int t, int x[], int y[], const vector<array<int, 2>>& v, int k) { for (int i = 0; i < b; i++) ycounts[i] = 0; int j = t-1; while (j >= 0 && v[j][0] >= x[a-1]) if (!insert_to_ycounts(y, b, v[j--][1])) return false; multiset<int> m; for (int i = a-1; i >= 0; i--) { while (j >= 0 && (i == 0 || v[j][0] >= x[i-1])) m.insert(v[j--][1]); while (ceil_div(m.size(), a - i) > k) if (!insert_to_ycounts(y, b, *m.begin())) return false; else m.erase(m.begin()); debug(i, j, ycounts, m); } int prefix = 0; for (int i = b-1; i >= 0; i--) { prefix += ycounts[i]; if (ceil_div(prefix, b - i) > k) return false; } return true; } bool insert_to_ycounts(int y[], int b, int val) { int index = upper_bound(y, y + b, val) - y; if (index == b) return false; ycounts[index]++; return true; } int ceil_div(int a, int b) { return (a + b - 1) / b; }

Compilation message (stderr)

robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:38:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |   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...