답안 #575102

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575102 2022-06-09T16:59:15 Z MadokaMagicaFan 도서관 (JOI18_library) C++14
100 / 100
495 ms 300 KB
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
const ll inf = 1e9;
const int md1 = 1e9+7;
const int md2 = 998244353;

#define sz(v)                       ((int)v.size())
#define pb                          push_back

#define pry                         cout << "YES\n"
#define prn                         cout << "NO\n"
#define endl                        '\n'

#define fst                         first
#define scn                         second
/* #define ONPC */

const int N = 1e3;
bitset<N+5> c;
vector<int> m;
int n;

int Query(const vector<int> &M);
void Answer(const vector<int> &res);

bool
comp(int l, int r, int x)
{
    for (int i = 0; i < n; ++i) {
        m[i] = 0;
    }

    int cnt = 0;
    for (int i = 1; i < n+1; ++i) {
        if (c[i])
            continue;
        if (cnt >= l && cnt < r)
            m[i-1] = 1;
        ++cnt;
    }
    int a1 = Query(m);
    m[x-1] = 1;
    int a2 = Query(m);

    return (a1 == a2);
}

int
arrsize()
{
    int s = 0;
    for (int i = 1; i < n+1; ++i) {
        if (!c[i])
            ++s;
    }
    return s;
}

int
getval(int l)
{
    for (int i = 1; i < n+1; ++i) {
        if (c[i])
            continue;
        --l;
        if (!l)
            return i;
    }
    return -1;
}

int
bs(int x)
{
    int l = 0;
    int r = arrsize();
    if (r == 1)
        return getval(1);
    if (r == 0)
        return 0;
    int mid;

    while (l < r-1) {
        mid = (l+r)>>1;
        if (comp(l,mid,x))
            r = mid;
        else
            l = mid;
    }

    return getval(l+1);
}

void
Solve(int _n)
{
    n = _n;
    if (n == 1) {
        vector<int> ans(1);
        ans[0] = 1;
        Answer(ans);
        return;
    }
    m.assign(n,1);
    int val = -1;
    for (int i = 1; i < n+1; ++i) {
        m[i-1] = 0;
        if (Query(m) == 1) {
            val = i;
            break;
        }
        m[i-1] = 1;
    }
    c[val] = 1;
    vector<int> ans;
    ans.pb(val);

    int cnt = 1;
    while (1) {
        val = bs(val);
        assert(val != -1);
        if (!val)
            break;
        c[val] = 1;
        ans.pb(val);
        ++ cnt;
    }

    Answer(ans);

    return;
}


#ifdef ONPC
vector<int> p;
int rn;

int 
Query(const vector<int> &M)
{
    int ans = 0;
    if (M[p[0]-1])
        ++ans;

    for (int i = 1; i < rn; ++i) {
        if(M[p[i-1]-1] == 0 && M[p[i]-1] == 1)
            ++ans;
    }

    assert(ans != 0);

    return ans;
}
void 
Answer(const vector<int> &res)
{
    for (int i = 0; i < rn; ++i) {
        cout << res[i] << ' ';
    }
    cout << endl;
}

void
solve()
{
    cin >> rn;
    p.resize(rn);
    cout << rn << endl;

    for (int i = 0; i < rn; ++i) {
        cin >> p[i];
    }

    Solve(rn);
}

int32_t
main(int argc, char **argv)
{
    if (argc >= 2) {
        freopen(argv[1], "r", stdin);
    } else
        ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    /* cin >> t; */
    while(t--)
        solve();
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 208 KB # of queries: 2375
2 Correct 38 ms 208 KB # of queries: 2409
3 Correct 37 ms 208 KB # of queries: 2648
4 Correct 35 ms 208 KB # of queries: 2595
5 Correct 35 ms 296 KB # of queries: 2508
6 Correct 35 ms 208 KB # of queries: 2551
7 Correct 39 ms 208 KB # of queries: 2544
8 Correct 33 ms 284 KB # of queries: 2420
9 Correct 40 ms 208 KB # of queries: 2546
10 Correct 26 ms 280 KB # of queries: 1474
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 1
13 Correct 0 ms 208 KB # of queries: 4
14 Correct 1 ms 208 KB # of queries: 7
15 Correct 1 ms 208 KB # of queries: 77
16 Correct 2 ms 208 KB # of queries: 183
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 208 KB # of queries: 2375
2 Correct 38 ms 208 KB # of queries: 2409
3 Correct 37 ms 208 KB # of queries: 2648
4 Correct 35 ms 208 KB # of queries: 2595
5 Correct 35 ms 296 KB # of queries: 2508
6 Correct 35 ms 208 KB # of queries: 2551
7 Correct 39 ms 208 KB # of queries: 2544
8 Correct 33 ms 284 KB # of queries: 2420
9 Correct 40 ms 208 KB # of queries: 2546
10 Correct 26 ms 280 KB # of queries: 1474
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 1
13 Correct 0 ms 208 KB # of queries: 4
14 Correct 1 ms 208 KB # of queries: 7
15 Correct 1 ms 208 KB # of queries: 77
16 Correct 2 ms 208 KB # of queries: 183
17 Correct 419 ms 288 KB # of queries: 17982
18 Correct 478 ms 284 KB # of queries: 17293
19 Correct 495 ms 280 KB # of queries: 17467
20 Correct 375 ms 284 KB # of queries: 16325
21 Correct 357 ms 284 KB # of queries: 15324
22 Correct 480 ms 292 KB # of queries: 17669
23 Correct 454 ms 288 KB # of queries: 17224
24 Correct 142 ms 208 KB # of queries: 7915
25 Correct 448 ms 284 KB # of queries: 17136
26 Correct 343 ms 288 KB # of queries: 15963
27 Correct 131 ms 288 KB # of queries: 8040
28 Correct 377 ms 284 KB # of queries: 15957
29 Correct 368 ms 300 KB # of queries: 15939
30 Correct 393 ms 288 KB # of queries: 15957