Submission #639836

#TimeUsernameProblemLanguageResultExecution timeMemory
639836ghostwriterRobots (IOI13_robots)C++14
76 / 100
3100 ms24840 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 + 5;
const int N = 5e4 + 5;
int a, b, t, x[N], y[N];
pi c[T];
bool cmp(pi &a, pi &b) { return a.st < b.st; }
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 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);
    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;
}

Compilation message (stderr)

robots.cpp: In function 'bool 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:48:5: note: in expansion of macro 'FOR'
   48 |     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:54:9: note: in expansion of macro 'FOR'
   54 |         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:57:5: note: in expansion of macro 'FOR'
   57 |     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:73:5: note: in expansion of macro 'FOR'
   73 |     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:74:5: note: in expansion of macro 'FOR'
   74 |     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:75:5: note: in expansion of macro 'FOR'
   75 |     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...