Submission #639840

#TimeUsernameProblemLanguageResultExecution timeMemory
639840ghostwriterRobots (IOI13_robots)C++14
100 / 100
1595 ms21044 KiB
#include "robots.h" #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #include "grader.c" #endif #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* Tran The Bao CTL - Da Lat Cay ngay cay dem nhung deo duoc cong nhan */ #pragma GCC optimize ("Ofast") #pragma GCC target ("avx,avx2") const int T = 1e6 + 1; const int N = 5e4 + 1; int a, b, t, x[N], y[N]; pi c[T]; bool cmp(pi &a, pi &b) { return a.st < b.st; } namespace subtask134 { bool check(int m) { multiset<int> s; int l = 1; FOR(i, 1, a) { WHILE(l <= t && c[l].st < x[i]) { s.insert(c[l].nd); ++l; } int cnt = min(m, sz(s)); FOR(j, 1, cnt) s.erase(--s.end()); } WHILE(l <= t) s.insert(c[l++].nd); FOR(i, 1, b) { int cnt = 0; WHILE(cnt < m && !s.empty()) { int cur = *s.begin(); if (cur >= y[i]) break; s.erase(s.begin()); ++cnt; } } if (!s.empty()) return 0; return 1; } int solve() { int l = 1, r = t, ans = -1; WHILE(l <= r) { int mid = l + (r - l) / 2; if (check(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } return ans; } } namespace subtask2 { bool check(int m) { int l = 1, total = 0; FOR(i, 1, a) { WHILE(l <= t && c[l].st < x[i]) { ++total; ++l; } total -= min(m, total); } total += t - l + 1; return total == 0; } int solve() { int l = 1, r = t, ans = -1; WHILE(l <= r) { int mid = l + (r - l) / 2; if (check(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } return ans; } } namespace subtask5 { int c1[T]; bool check(int m) { memset(c1, 0, sizeof c1); priority_queue<pi> pq; int l = 1; FOR(i, 1, a) { WHILE(l <= t && c[l].st < x[i]) { pq.push({c[l].nd, l}); ++l; } int cnt = min(m, sz(pq)); FOR(j, 1, cnt) { auto cur = pq.top(); c1[cur.nd] = 1; pq.pop(); } } vi a1; FOR(i, 1, t) if (!c1[i]) a1.pb(c[i].nd); sort(all(a1)); l = 0; FOR(i, 1, b) { int cnt = 0; WHILE(cnt < m && l < sz(a1)) { int cur = a1[l]; if (cur >= y[i]) break; ++l; ++cnt; } } if (l < sz(a1)) return 0; return 1; } int solve() { int l = 1, r = t, ans = -1; WHILE(l <= r) { int mid = l + (r - l) / 2; if (check(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } return ans; } } int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { a = A; b = B; t = T; FOR(i, 1, a) x[i] = X[i - 1]; FOR(i, 1, b) y[i] = Y[i - 1]; FOR(i, 1, t) c[i] = {W[i - 1], S[i - 1]}; sort(x + 1, x + 1 + a); sort(y + 1, y + 1 + b); sort(c + 1, c + 1 + t, cmp); if (t <= 1e4) return subtask134::solve(); if (b == 0) return subtask2::solve(); return subtask5::solve(); }

Compilation message (stderr)

robots.cpp: In function 'bool subtask134::check(int)':
robots.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
robots.cpp:49:9: note: in expansion of macro 'FOR'
   49 |         FOR(i, 1, a) {
      |         ^~~
robots.cpp:26:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
robots.cpp:55:13: note: in expansion of macro 'FOR'
   55 |             FOR(j, 1, cnt) s.erase(--s.end());
      |             ^~~
robots.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
robots.cpp:58:9: note: in expansion of macro 'FOR'
   58 |         FOR(i, 1, b) {
      |         ^~~
robots.cpp: In function 'bool subtask2::check(int)':
robots.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
robots.cpp:86:9: note: in expansion of macro 'FOR'
   86 |         FOR(i, 1, a) {
      |         ^~~
robots.cpp: In function 'bool subtask5::check(int)':
robots.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
robots.cpp:115:9: note: in expansion of macro 'FOR'
  115 |         FOR(i, 1, a) {
      |         ^~~
robots.cpp:26:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
robots.cpp:121:13: note: in expansion of macro 'FOR'
  121 |             FOR(j, 1, cnt) {
      |             ^~~
robots.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
robots.cpp:128:9: note: in expansion of macro 'FOR'
  128 |         FOR(i, 1, t)
      |         ^~~
robots.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
robots.cpp:133:9: note: in expansion of macro 'FOR'
  133 |         FOR(i, 1, b) {
      |         ^~~
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
robots.cpp:162:5: note: in expansion of macro 'FOR'
  162 |     FOR(i, 1, a) x[i] = X[i - 1];
      |     ^~~
robots.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
robots.cpp:163:5: note: in expansion of macro 'FOR'
  163 |     FOR(i, 1, b) y[i] = Y[i - 1];
      |     ^~~
robots.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
robots.cpp:164:5: note: in expansion of macro 'FOR'
  164 |     FOR(i, 1, t) c[i] = {W[i - 1], S[i - 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...