Submission #825215

# Submission time Handle Problem Language Result Execution time Memory
825215 2023-08-14T15:44:32 Z vjudge1 Library (JOI18_library) C++17
100 / 100
245 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);
        vector<int> rem(N);
        iota(rem.begin(), rem.end(), 1);
        while (true) {
                for (int i = 0; i < rem.size(); i++) {
                        if (rem[i] == res.back()) {
                                swap(rem[i], rem.back());
                                rem.pop_back();
                                break;
                        }
                }
                if (rem.size() == 1) {
                        res.emplace_back(rem[0]);
                        return void(Answer(res));
                }
                int l = 1, r = rem.size(), nxt = -1;
                while (l <= r) {
                        int mid = l + r >> 1;
                        ask = vector<int>(N, 0);
                        for (int i = 0; i < mid; i++) ask[rem[i] - 1] = 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;
                        }
                }
                res.emplace_back(rem[nxt - 1]);
        }
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:25:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |                 for (int i = 0; i < rem.size(); i++) {
      |                                 ~~^~~~~~~~~~~~
library.cpp:38:37: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |                         int mid = l + r >> 1;
      |                                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 336 KB # of queries: 2578
2 Correct 23 ms 300 KB # of queries: 2567
3 Correct 26 ms 208 KB # of queries: 2708
4 Correct 26 ms 300 KB # of queries: 2708
5 Correct 25 ms 300 KB # of queries: 2722
6 Correct 31 ms 208 KB # of queries: 2710
7 Correct 22 ms 208 KB # of queries: 2718
8 Correct 30 ms 208 KB # of queries: 2573
9 Correct 28 ms 208 KB # of queries: 2687
10 Correct 14 ms 208 KB # of queries: 1585
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 1 ms 208 KB # of queries: 2
13 Correct 0 ms 208 KB # of queries: 5
14 Correct 0 ms 208 KB # of queries: 12
15 Correct 1 ms 208 KB # of queries: 93
16 Correct 2 ms 208 KB # of queries: 211
# Verdict Execution time Memory Grader output
1 Correct 23 ms 336 KB # of queries: 2578
2 Correct 23 ms 300 KB # of queries: 2567
3 Correct 26 ms 208 KB # of queries: 2708
4 Correct 26 ms 300 KB # of queries: 2708
5 Correct 25 ms 300 KB # of queries: 2722
6 Correct 31 ms 208 KB # of queries: 2710
7 Correct 22 ms 208 KB # of queries: 2718
8 Correct 30 ms 208 KB # of queries: 2573
9 Correct 28 ms 208 KB # of queries: 2687
10 Correct 14 ms 208 KB # of queries: 1585
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 1 ms 208 KB # of queries: 2
13 Correct 0 ms 208 KB # of queries: 5
14 Correct 0 ms 208 KB # of queries: 12
15 Correct 1 ms 208 KB # of queries: 93
16 Correct 2 ms 208 KB # of queries: 211
17 Correct 192 ms 300 KB # of queries: 18210
18 Correct 218 ms 292 KB # of queries: 17925
19 Correct 245 ms 292 KB # of queries: 18182
20 Correct 165 ms 296 KB # of queries: 16920
21 Correct 194 ms 304 KB # of queries: 15939
22 Correct 214 ms 292 KB # of queries: 18194
23 Correct 181 ms 300 KB # of queries: 18153
24 Correct 82 ms 288 KB # of queries: 8313
25 Correct 189 ms 296 KB # of queries: 17749
26 Correct 207 ms 292 KB # of queries: 16603
27 Correct 84 ms 300 KB # of queries: 8293
28 Correct 206 ms 304 KB # of queries: 18952
29 Correct 224 ms 328 KB # of queries: 18931
30 Correct 227 ms 332 KB # of queries: 18952