답안 #622307

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
622307 2022-08-04T07:02:42 Z maomao90 Shopping (JOI21_shopping) C++17
91 / 100
240 ms 16248 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
#include "Anna.h"
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 1000005;
const int BLK = 1384;

namespace {
    int n, l, r;
    vector<bool> bits;
    int ans;
}

void InitA(int N, int L, int R) {
    n = N; l = L; r = R;
    int lb = l / BLK, rb = r / BLK;
    int bn = (n - 1) / BLK + 1;
    int id = 0;
    REP (i, 0, lb) {
        id += bn - i;
    }
    id += rb - lb;
    RREP (k, 17, 0) {
        SendA(id >> k & 1);
    }
    ans = -1;
}

void ReceiveA(bool x) {
    bits.pb(x);
    if (SZ(bits) == (2 * BLK + 1) * 2) {
        int lb = l / BLK, rb = r / BLK;
        int bn = (n - 1) / BLK + 1;
        if (lb == rb) {
            int id = lb * BLK;
            vi stk;
            for (bool x : bits) {
                if (x) {
                    if (id >= l) {
                        stk.pb(id);
                    }
                    if (id == r) {
                        ans = stk[0];
                        return;
                    }
                    id++;
                } else {
                    if (!stk.empty()) {
                        stk.pop_back();
                    }
                }
            }
        } else {
            int mid = 0;
            REP (k, 0, 20) {
                mid += bits.back() << k;
                bits.pop_back();
            }
            int id = lb * BLK;
            vi stk;
            for (bool x : bits) {
                if (x) {
                    if (id >= l) {
                        stk.pb(id);
                    }
                    if (id == r) {
                        ans = stk[0];
                        return;
                    }
                    id++;
                    if (id == (lb + 1) * BLK) {
                        id = mid;
                    } else if (id == mid + 1) {
                        id = rb * BLK;
                    }
                } else {
                    if (!stk.empty()) {
                        stk.pop_back();
                    }
                }
            }
        }
    }
}

int Answer() {
    assert(ans != -1);
    return ans;
}
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
#include "Bruno.h"
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 1000005;
const int BLK = 1384;

namespace {
    int n;
    vi p;
    int cnt;
    int id;
}

void InitB(int N, vi P) {
    n = N; p = P;
    cnt = 0;
    id = 0;
    while (n % BLK != 0) {
        n++;
        p.pb(INF);
    }
}

void ReceiveB(bool y) {
    id *= 2;
    id += y;
    if (++cnt == 18) {
        int bn = (n - 1) / BLK + 1;
        int lb = -1, rb = -1;
        REP (i, 0, bn) {
            if (bn - i <= id) {
                id -= bn - i;
            } else {
                lb = i;
                rb = i + id;
                break;
            }
        }
        assert(lb != -1);
        vi stk;
        REP (i, lb * BLK, (lb + 1) * BLK) {
            while (!stk.empty() && stk.back() >= p[i]) {
                SendB(0);
                stk.pop_back();
            }
            SendB(1);
            stk.pb(p[i]);
        }
        ii mid = {INF, 0};
        if (lb < rb) {
            REP (i, (lb + 1) * BLK, rb * BLK) {
                mnto(mid, {p[i], i});
            }
        }
        while (!stk.empty() && stk.back() >= mid.FI) {
            SendB(0);
            stk.pop_back();
        }
        SendB(1);
        stk.pb(mid.FI);
        REP (i, rb * BLK, (rb + 1) * BLK) {
            while (!stk.empty() && stk.back() >= p[i]) {
                SendB(0);
                stk.pop_back();
            }
            SendB(1);
            stk.pb(p[i]);
        }
        while (!stk.empty()) {
            SendB(0);
            stk.pop_back();
        }
        RREP (k, 19, 0) {
            SendB(mid.SE >> k & 1);
        }
    }
    assert(cnt <= 18);
}

Compilation message

Anna.cpp: In function 'void ReceiveA(bool)':
Anna.cpp:65:13: warning: unused variable 'bn' [-Wunused-variable]
   65 |         int bn = (n - 1) / BLK + 1;
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 484 KB Output is correct
2 Correct 53 ms 608 KB Output is correct
3 Correct 54 ms 476 KB Output is correct
4 Correct 54 ms 508 KB Output is correct
5 Correct 47 ms 472 KB Output is correct
6 Correct 63 ms 584 KB Output is correct
7 Correct 48 ms 476 KB Output is correct
8 Correct 55 ms 480 KB Output is correct
9 Correct 56 ms 588 KB Output is correct
10 Correct 61 ms 512 KB Output is correct
11 Correct 24 ms 400 KB Output is correct
12 Correct 53 ms 472 KB Output is correct
13 Correct 52 ms 472 KB Output is correct
14 Correct 51 ms 476 KB Output is correct
15 Correct 43 ms 492 KB Output is correct
16 Correct 40 ms 480 KB Output is correct
17 Correct 57 ms 476 KB Output is correct
18 Correct 69 ms 480 KB Output is correct
19 Correct 46 ms 512 KB Output is correct
20 Correct 50 ms 560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 484 KB Output is correct
2 Correct 53 ms 608 KB Output is correct
3 Correct 54 ms 476 KB Output is correct
4 Correct 54 ms 508 KB Output is correct
5 Correct 47 ms 472 KB Output is correct
6 Correct 63 ms 584 KB Output is correct
7 Correct 48 ms 476 KB Output is correct
8 Correct 55 ms 480 KB Output is correct
9 Correct 56 ms 588 KB Output is correct
10 Correct 61 ms 512 KB Output is correct
11 Correct 24 ms 400 KB Output is correct
12 Correct 53 ms 472 KB Output is correct
13 Correct 52 ms 472 KB Output is correct
14 Correct 51 ms 476 KB Output is correct
15 Correct 43 ms 492 KB Output is correct
16 Correct 40 ms 480 KB Output is correct
17 Correct 57 ms 476 KB Output is correct
18 Correct 69 ms 480 KB Output is correct
19 Correct 46 ms 512 KB Output is correct
20 Correct 50 ms 560 KB Output is correct
21 Correct 37 ms 632 KB Output is correct
22 Correct 45 ms 656 KB Output is correct
23 Correct 56 ms 724 KB Output is correct
24 Correct 45 ms 788 KB Output is correct
25 Correct 25 ms 708 KB Output is correct
26 Correct 48 ms 740 KB Output is correct
27 Correct 37 ms 732 KB Output is correct
28 Correct 33 ms 656 KB Output is correct
29 Correct 50 ms 740 KB Output is correct
30 Correct 44 ms 724 KB Output is correct
31 Correct 47 ms 728 KB Output is correct
32 Incorrect 41 ms 200 KB Wrong Answer [2]
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 15928 KB Output is correct
2 Correct 166 ms 16112 KB Output is correct
3 Correct 146 ms 16096 KB Output is correct
4 Correct 143 ms 16172 KB Output is correct
5 Correct 162 ms 16116 KB Output is correct
6 Correct 161 ms 16112 KB Output is correct
7 Correct 133 ms 16108 KB Output is correct
8 Correct 173 ms 16120 KB Output is correct
9 Correct 102 ms 16160 KB Output is correct
10 Correct 154 ms 16112 KB Output is correct
11 Correct 128 ms 16108 KB Output is correct
12 Correct 126 ms 16112 KB Output is correct
13 Correct 109 ms 16220 KB Output is correct
14 Correct 197 ms 16112 KB Output is correct
15 Correct 144 ms 16084 KB Output is correct
16 Correct 143 ms 16116 KB Output is correct
17 Correct 138 ms 16248 KB Output is correct
18 Correct 134 ms 16208 KB Output is correct
19 Correct 218 ms 16104 KB Output is correct
20 Correct 148 ms 16120 KB Output is correct
21 Correct 161 ms 16152 KB Output is correct
22 Correct 134 ms 16140 KB Output is correct
23 Correct 132 ms 16120 KB Output is correct
24 Correct 185 ms 16156 KB Output is correct
25 Correct 147 ms 16192 KB Output is correct
26 Correct 163 ms 16040 KB Output is correct
27 Correct 186 ms 16120 KB Output is correct
28 Correct 240 ms 16104 KB Output is correct
29 Correct 148 ms 16116 KB Output is correct
30 Correct 145 ms 16208 KB Output is correct