답안 #825180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825180 2023-08-14T15:08:52 Z vjudge1 도서관 (JOI18_library) C++17
19 / 100
234 ms 328 KB
#include "library.h"

#include <bits/stdc++.h>

#include <cstdio>
#include <vector>
using namespace std;

void Solve(int N) {
        if (N == 1) return void(Answer({1}));
        vector<int> ask(N, 1);
        int start = -1;
        for (int i = 0; i < N; i++) {
                ask[i] = 0;
                if (Query(ask) == 1) {
                        start = i;
                }
                ask[i] = 1;
        }
        // assert(start != -1);
        vector<int> res(1, start + 1);
        while (res.size() != N - 1) {
                int l = 1, r = N, nxt = -1;
                while (l <= r) {
                        int mid = l + r >> 1;
                        ask = vector<int>(N, 0);
                        for (int i = 0; i < mid; i++) ask[i] = 1;
                        for (int i : res) ask[i - 1] = 1;
                        int x = Query(ask);
                        for (int i : res) ask[i - 1] = 0;
                        int y = count(ask.begin(), ask.end(), 1) ? Query(ask) : 0;
                        if (x == y) {
                                nxt = mid;
                                r = mid - 1;
                        } else {
                                l = mid + 1;
                        }
                }
                // assert(nxt != -1);
                res.emplace_back(nxt);
        }
        vector<int> vis(N, 0);
        for (int x : res) vis[x - 1] = 1;
        for (int i = 0; i < N; i++) {
                if (!vis[i]) res.emplace_back(i + 1);
        }
        Answer(res);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:22:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |         while (res.size() != N - 1) {
      |                ~~~~~~~~~~~^~~~~~~~
library.cpp:25:37: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |                         int mid = l + r >> 1;
      |                                   ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 208 KB # of queries: 3101
2 Correct 38 ms 296 KB # of queries: 3066
3 Correct 33 ms 208 KB # of queries: 3251
4 Correct 29 ms 208 KB # of queries: 3244
5 Correct 32 ms 208 KB # of queries: 3255
6 Correct 27 ms 296 KB # of queries: 3255
7 Correct 31 ms 208 KB # of queries: 3247
8 Correct 33 ms 208 KB # of queries: 3123
9 Correct 34 ms 208 KB # of queries: 3237
10 Correct 22 ms 208 KB # of queries: 1904
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 2
13 Correct 1 ms 208 KB # of queries: 7
14 Correct 0 ms 208 KB # of queries: 12
15 Correct 1 ms 208 KB # of queries: 119
16 Correct 2 ms 208 KB # of queries: 265
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 208 KB # of queries: 3101
2 Correct 38 ms 296 KB # of queries: 3066
3 Correct 33 ms 208 KB # of queries: 3251
4 Correct 29 ms 208 KB # of queries: 3244
5 Correct 32 ms 208 KB # of queries: 3255
6 Correct 27 ms 296 KB # of queries: 3255
7 Correct 31 ms 208 KB # of queries: 3247
8 Correct 33 ms 208 KB # of queries: 3123
9 Correct 34 ms 208 KB # of queries: 3237
10 Correct 22 ms 208 KB # of queries: 1904
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 2
13 Correct 1 ms 208 KB # of queries: 7
14 Correct 0 ms 208 KB # of queries: 12
15 Correct 1 ms 208 KB # of queries: 119
16 Correct 2 ms 208 KB # of queries: 265
17 Runtime error 234 ms 328 KB Execution killed with signal 13
18 Halted 0 ms 0 KB -