Submission #781927

#TimeUsernameProblemLanguageResultExecution timeMemory
781927caganyanmazRobots (IOI13_robots)C++17
100 / 100
2749 ms44172 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #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[], int k); int ceil_div(int a, int b); constexpr static int MXTOYSIZE = 1e6; constexpr static int MXSIZE = 50000; map<int, int> xdata[MXSIZE+1]; int putaway(int a, int b, int t, int x[], int y[], int ww[], int ss[]) { sort(x, x + a); sort(y, y + b); for (int i = 0; i < t; i++) { int index = upper_bound(x, x + a, ww[i]) - x; int yindex = upper_bound(y, y + b, ss[i]) - y; if (xdata[index].find(yindex) == xdata[index].end()) xdata[index][yindex] = 0; xdata[index][yindex]++; } int l = 0, r = t+1; while (r - l > 1) { int m = l+r>>1; if (is_possible(a, b, t, x, y, m)) r = m; else l = m; } if (r == t+1) return -1; return r; } 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[], int k) { fill(ycounts, ycounts + b, 0); map<int, int> current_counts; int cost = 0; for (int i = a; i >= 0; i--) { for (auto it = xdata[i].begin(); it != xdata[i].end(); it++) cost += it->second; for (auto it = current_counts.begin(), jt = xdata[i].end(); it != current_counts.end() && jt != xdata[i].end();) { if (it->first == jt->first) { it++; jt++; } else if (it->first > jt->first) { jt++; } else { it++; } } current_counts.insert(xdata[i].begin(), xdata[i].end()); while (cost && (i == a || ceil_div(cost, a - i) > k)) { if (current_counts.begin()->first == b) { return false; } else { cost--; ycounts[current_counts.begin()->first]++; current_counts.begin()->second--; if (!current_counts.begin()->second) current_counts.erase(current_counts.begin()); } } } int j = t-1; 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; } 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:46:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |   int m = l+r>>1;
      |           ~^~
robots.cpp: In function 'bool is_possible(int, int, int, int*, int*, int)':
robots.cpp:101:6: warning: unused variable 'j' [-Wunused-variable]
  101 |  int j = t-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...