답안 #575091

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575091 2022-06-09T16:31:33 Z MadokaMagicaFan 도서관 (JOI18_library) C++14
0 / 100
1 ms 208 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) {
        mid = (l+r)>>1;
        if (comp(l,mid,x))
            r = mid;
        else
            l = mid+1;
    }

    return getval(l);
}

void
Solve(int _n)
{
    n = _n;
    assert(n != 1);
    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);

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

    Answer(ans);

    return;
}


#ifdef ONPC
void
solve()
{

}

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 Runtime error 1 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -