Submission #633329

#TimeUsernameProblemLanguageResultExecution timeMemory
633329ghostwriterCave (IOI13_cave)C++14
100 / 100
954 ms672 KiB
#include "cave.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
    Practising for VOI23 gold medal
*/
const int MAXN = 5000;
int b[MAXN], s[MAXN], a[MAXN];
void exploreCave(int N) {
    memset(a, -1, sizeof a);
    FOR(i, 0, N - 1) {
        FOR(j, 0, N - 1)
            if (a[j] != -1) b[j] = s[j];
            else b[j] = 0;
        int tmp = tryCombination(b), val = -1;
        if (tmp == -1 || tmp > i) val = 0;
        else val = 1;
        int l = 0, r = N - 1, ans = -1;
        WHILE(l <= r) {
            int mid = l + (r - l) / 2;
            FOR(j, 0, N - 1)
                if (a[j] != -1) b[j] = s[j];
                else if (j <= mid) b[j] = val;
                else b[j] = val ^ 1;
            int tmp = tryCombination(b);
            if (tmp == -1 || tmp > i) {
                ans = mid;
                r = mid - 1;
            }
            else l = mid + 1;
        }
        s[ans] = val;
        a[ans] = i;
    }
    answer(s, a);
}

Compilation message (stderr)

cave.cpp: In function 'void exploreCave(int)':
cave.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
cave.cpp:42:5: note: in expansion of macro 'FOR'
   42 |     FOR(i, 0, N - 1) {
      |     ^~~
cave.cpp:26:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
cave.cpp:43:9: note: in expansion of macro 'FOR'
   43 |         FOR(j, 0, N - 1)
      |         ^~~
cave.cpp:26:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
cave.cpp:52:13: note: in expansion of macro 'FOR'
   52 |             FOR(j, 0, N - 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...