Submission #825171

# Submission time Handle Problem Language Result Execution time Memory
825171 2023-08-14T14:58:49 Z vjudge1 Library (JOI18_library) C++17
19 / 100
174 ms 336 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;
      |                                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 304 KB # of queries: 3101
2 Correct 36 ms 300 KB # of queries: 3066
3 Correct 35 ms 208 KB # of queries: 3251
4 Correct 34 ms 208 KB # of queries: 3244
5 Correct 38 ms 296 KB # of queries: 3255
6 Correct 32 ms 296 KB # of queries: 3255
7 Correct 29 ms 336 KB # of queries: 3247
8 Correct 34 ms 208 KB # of queries: 3123
9 Correct 26 ms 304 KB # of queries: 3237
10 Correct 19 ms 304 KB # of queries: 1904
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 2
13 Correct 0 ms 208 KB # of queries: 7
14 Correct 1 ms 208 KB # of queries: 12
15 Correct 2 ms 208 KB # of queries: 119
16 Correct 3 ms 208 KB # of queries: 265
# Verdict Execution time Memory Grader output
1 Correct 38 ms 304 KB # of queries: 3101
2 Correct 36 ms 300 KB # of queries: 3066
3 Correct 35 ms 208 KB # of queries: 3251
4 Correct 34 ms 208 KB # of queries: 3244
5 Correct 38 ms 296 KB # of queries: 3255
6 Correct 32 ms 296 KB # of queries: 3255
7 Correct 29 ms 336 KB # of queries: 3247
8 Correct 34 ms 208 KB # of queries: 3123
9 Correct 26 ms 304 KB # of queries: 3237
10 Correct 19 ms 304 KB # of queries: 1904
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 2
13 Correct 0 ms 208 KB # of queries: 7
14 Correct 1 ms 208 KB # of queries: 12
15 Correct 2 ms 208 KB # of queries: 119
16 Correct 3 ms 208 KB # of queries: 265
17 Runtime error 174 ms 300 KB Execution killed with signal 13
18 Halted 0 ms 0 KB -