답안 #995079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995079 2024-06-08T12:13:20 Z otarius 도서관 (JOI18_library) C++17
100 / 100
243 ms 600 KB
#include "library.h"
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define sc second
#define pb push_back
#define pii pair<int, int>

void Solve(int n) {
    vector<int> ans(n);
    vector<int> v(n, 1);
    bool used[n + 1] = {};
    if (n == 1) {
        ans[0] = 1;
        Answer(ans);
        return;
    }
    for (int i = 1; i <= n; i++) {
        v[i - 1] = 0;
        if (Query(v) == 1) {
            ans[0] = i; used[i] = 1; break;
        } v[i - 1] = 1;
    }
    for (int i = 2; i < n; i++) {
        vector<int> cur;
        for (int j = 1; j <= n; j++)
            if (!used[j]) cur.pb(j);
        int l = 0, r = cur.size() - 1, m, an;
        while (l <= r) {
            m = (l + r) / 2;
            for (int &k : v) k = 0;
            v[ans[i - 2] - 1] = 1;
            for (int k = 0; k <= m; k++)
                v[cur[k] - 1] = 1;
            int vl = Query(v);
            v[ans[i - 2] - 1] = 0;
            if (Query(v) == vl) {
                an = m; r = m - 1;
            } else l = m + 1;
        } ans[i - 1] = cur[an]; used[cur[an]] = 1;
    } for (int i = 1; i <= n; i++)
        if (!used[i]) ans[n - 1] = i;
    Answer(ans);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:40:30: warning: 'an' may be used uninitialized in this function [-Wmaybe-uninitialized]
   40 |         } ans[i - 1] = cur[an]; used[cur[an]] = 1;
      |                              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 344 KB # of queries: 2399
2 Correct 14 ms 344 KB # of queries: 2435
3 Correct 24 ms 344 KB # of queries: 2656
4 Correct 17 ms 344 KB # of queries: 2595
5 Correct 30 ms 344 KB # of queries: 2524
6 Correct 26 ms 344 KB # of queries: 2563
7 Correct 25 ms 344 KB # of queries: 2554
8 Correct 20 ms 344 KB # of queries: 2422
9 Correct 24 ms 344 KB # of queries: 2548
10 Correct 13 ms 344 KB # of queries: 1486
11 Correct 1 ms 344 KB # of queries: 0
12 Correct 0 ms 344 KB # of queries: 1
13 Correct 1 ms 344 KB # of queries: 4
14 Correct 0 ms 344 KB # of queries: 7
15 Correct 1 ms 344 KB # of queries: 77
16 Correct 1 ms 344 KB # of queries: 193
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 344 KB # of queries: 2399
2 Correct 14 ms 344 KB # of queries: 2435
3 Correct 24 ms 344 KB # of queries: 2656
4 Correct 17 ms 344 KB # of queries: 2595
5 Correct 30 ms 344 KB # of queries: 2524
6 Correct 26 ms 344 KB # of queries: 2563
7 Correct 25 ms 344 KB # of queries: 2554
8 Correct 20 ms 344 KB # of queries: 2422
9 Correct 24 ms 344 KB # of queries: 2548
10 Correct 13 ms 344 KB # of queries: 1486
11 Correct 1 ms 344 KB # of queries: 0
12 Correct 0 ms 344 KB # of queries: 1
13 Correct 1 ms 344 KB # of queries: 4
14 Correct 0 ms 344 KB # of queries: 7
15 Correct 1 ms 344 KB # of queries: 77
16 Correct 1 ms 344 KB # of queries: 193
17 Correct 243 ms 344 KB # of queries: 18028
18 Correct 218 ms 344 KB # of queries: 17277
19 Correct 186 ms 344 KB # of queries: 17477
20 Correct 233 ms 344 KB # of queries: 16299
21 Correct 201 ms 344 KB # of queries: 15350
22 Correct 210 ms 344 KB # of queries: 17661
23 Correct 228 ms 344 KB # of queries: 17248
24 Correct 71 ms 344 KB # of queries: 7915
25 Correct 195 ms 344 KB # of queries: 17156
26 Correct 196 ms 344 KB # of queries: 16001
27 Correct 91 ms 600 KB # of queries: 8044
28 Correct 226 ms 344 KB # of queries: 15973
29 Correct 183 ms 344 KB # of queries: 15955
30 Correct 173 ms 344 KB # of queries: 15973