Submission #575098

# Submission time Handle Problem Language Result Execution time Memory
575098 2022-06-09T16:57:16 Z MadokaMagicaFan Library (JOI18_library) C++14
0 / 100
45 ms 336 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;
    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);

    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
# Verdict Execution time Memory Grader output
1 Correct 39 ms 208 KB # of queries: 2375
2 Correct 32 ms 208 KB # of queries: 2409
3 Correct 45 ms 208 KB # of queries: 2648
4 Correct 33 ms 208 KB # of queries: 2595
5 Correct 40 ms 208 KB # of queries: 2508
6 Correct 34 ms 300 KB # of queries: 2551
7 Correct 40 ms 208 KB # of queries: 2544
8 Correct 33 ms 208 KB # of queries: 2420
9 Correct 37 ms 208 KB # of queries: 2546
10 Correct 20 ms 288 KB # of queries: 1474
11 Runtime error 1 ms 336 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 208 KB # of queries: 2375
2 Correct 32 ms 208 KB # of queries: 2409
3 Correct 45 ms 208 KB # of queries: 2648
4 Correct 33 ms 208 KB # of queries: 2595
5 Correct 40 ms 208 KB # of queries: 2508
6 Correct 34 ms 300 KB # of queries: 2551
7 Correct 40 ms 208 KB # of queries: 2544
8 Correct 33 ms 208 KB # of queries: 2420
9 Correct 37 ms 208 KB # of queries: 2546
10 Correct 20 ms 288 KB # of queries: 1474
11 Runtime error 1 ms 336 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -