답안 #825163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825163 2023-08-14T14:55:12 Z vjudge1 도서관 (JOI18_library) C++17
0 / 100
40 ms 464 KB
#include "library.h"
/// 123
#include <bits/stdc++.h>

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

void Solve(int N) {
        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:21:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |         while (res.size() != N - 1) {
      |                ~~~~~~~~~~~^~~~~~~~
library.cpp:24:37: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |                         int mid = l + r >> 1;
      |                                   ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 280 KB # of queries: 3101
2 Correct 19 ms 300 KB # of queries: 3066
3 Correct 40 ms 208 KB # of queries: 3251
4 Correct 34 ms 300 KB # of queries: 3244
5 Correct 35 ms 208 KB # of queries: 3255
6 Correct 38 ms 208 KB # of queries: 3255
7 Correct 38 ms 208 KB # of queries: 3247
8 Correct 29 ms 208 KB # of queries: 3123
9 Correct 31 ms 208 KB # of queries: 3237
10 Correct 22 ms 300 KB # of queries: 1904
11 Runtime error 1 ms 464 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 280 KB # of queries: 3101
2 Correct 19 ms 300 KB # of queries: 3066
3 Correct 40 ms 208 KB # of queries: 3251
4 Correct 34 ms 300 KB # of queries: 3244
5 Correct 35 ms 208 KB # of queries: 3255
6 Correct 38 ms 208 KB # of queries: 3255
7 Correct 38 ms 208 KB # of queries: 3247
8 Correct 29 ms 208 KB # of queries: 3123
9 Correct 31 ms 208 KB # of queries: 3237
10 Correct 22 ms 300 KB # of queries: 1904
11 Runtime error 1 ms 464 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -