Submission #594074

# Submission time Handle Problem Language Result Execution time Memory
594074 2022-07-12T04:51:37 Z AA_Surely Library (JOI18_library) C++14
0 / 100
47 ms 308 KB
#include <bits/stdc++.h>
#include "library.h"

#define FOR(i, x, n)    for(int i = x; i < n; i++)
#define F0R(i, n)       FOR(i, 0, n)
#define ROF(i, x, n)    for(int i = n - 1; i >= x; i--)
#define R0F(i, n)       ROF(i, 0, n)

#define WTF             cout << "WTF" << endl;

#define IOS             ios_base::sync_with_stdio(0); cin.tie(0);
#define F               first
#define S               second
#define pb              push_back

#define ALL(x)          x.begin(), x.end()
#define RALL(x)         x.rbegin(), x.rend()

using namespace std;

typedef long long       LL;

typedef pair<int, int>  PII;
typedef pair<LL, LL>    PLL;

typedef vector<int>     VI;
typedef vector<LL>      VLL;
typedef vector<PII>     VPII;
typedef vector<PLL>     VPLL;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1000 + 7;

int n;
bool vis[N];
VI qr, opt, ans;

int findLeaf() {
    fill(ALL(qr), 1);

    F0R(i, n) {
        qr[i] = 0;
        
        //cout << "asking: "; F0R(i, n) cout << qr[i] << ' '; cout << endl;
        int z = Query(qr);
        qr[i] = 1;
        if (z == 1) return i;
    }

    return -1;
}

inline bool get(int x, int l, int r) {
    fill(ALL(qr), 0);
    FOR(i, l, r + 1) qr[ opt[i] ] = 1;
    int g1 = Query(qr);
    qr[x] = 1;
    int g2 = Query(qr);

    return g1 == g2;
}

int bs(int now, int l = 0, int r = opt.size()) {
    if (l == r) return opt[l];

    int mid = (l + r) >> 1;
    if (get(now, l, mid)) return bs(now, l, mid);
    return bs(now, mid + 1, r);
}

void Solve(int nn) {
    n = nn;
    if (n == 1) {
        cout << 1 << endl;
        return;
    }

    qr.resize(n);

    int now = findLeaf();
    ans.pb(now + 1);

    F0R(i, n - 1) {
        vis[now] = 1;
        qr[now] = 0;
        opt.clear();

        F0R(i, n) if (!vis[i]) opt.pb(i);
        //cout << "for i = " << i << " and now = " << now + 1 << " opt is ";
        //for(int on : opt) cout << on + 1 << ' '; cout << endl;

        int f = bs(now);
        ans.pb(f + 1);
        now = f;
    }

    //for(int on : ans) cout << on << ' '; cout << endl;
    Answer(ans);
    return;
}
# Verdict Execution time Memory Grader output
1 Correct 35 ms 300 KB # of queries: 2411
2 Correct 35 ms 304 KB # of queries: 2455
3 Correct 47 ms 300 KB # of queries: 2664
4 Correct 47 ms 208 KB # of queries: 2613
5 Correct 41 ms 256 KB # of queries: 2534
6 Correct 39 ms 208 KB # of queries: 2567
7 Correct 25 ms 308 KB # of queries: 2580
8 Correct 28 ms 208 KB # of queries: 2416
9 Correct 41 ms 208 KB # of queries: 2552
10 Correct 16 ms 208 KB # of queries: 1494
11 Incorrect 0 ms 208 KB DO NOT WRITE ANYTHING TO STANDARD OUTPUT
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 300 KB # of queries: 2411
2 Correct 35 ms 304 KB # of queries: 2455
3 Correct 47 ms 300 KB # of queries: 2664
4 Correct 47 ms 208 KB # of queries: 2613
5 Correct 41 ms 256 KB # of queries: 2534
6 Correct 39 ms 208 KB # of queries: 2567
7 Correct 25 ms 308 KB # of queries: 2580
8 Correct 28 ms 208 KB # of queries: 2416
9 Correct 41 ms 208 KB # of queries: 2552
10 Correct 16 ms 208 KB # of queries: 1494
11 Incorrect 0 ms 208 KB DO NOT WRITE ANYTHING TO STANDARD OUTPUT
12 Halted 0 ms 0 KB -