Submission #1080163

# Submission time Handle Problem Language Result Execution time Memory
1080163 2024-08-29T07:36:20 Z adaawf Library (JOI18_library) C++17
100 / 100
222 ms 688 KB
#include <iostream>
#include <vector>
#include <assert.h>
#include "library.h"
using namespace std;
int dd[1005];
/*int Query(vector<int> v) {
    for (int w : v) cout << w << " ";
    cout << endl;
    int x;
    cin >> x;
    return x;
}
void Answer(vector<int> v) {
    for (int w : v) cout << w << " ";
    cout << endl;
}*/
void Solve(int n) {
    if (n == 1) {
        Answer({1});
        return;
    }
    for (int i = 0; i < n; i++) dd[i] = 0;
    vector<int> res;
    for (int i = 0; i < n; i++) {
        vector<int> vv;
        for (int j = 0; j < n; j++) {
            if (i == j) vv.push_back(0);
            else vv.push_back(1);
        }
        if (Query(vv) == 1) {
            res.push_back(i);
            break;
        }
    }
    for (int i = 0; i < n; i++) {
        if (i == res.back()) continue;
        vector<int> vv;
        for (int j = 0; j < n; j++) {
            if (j == i || j == res.back()) vv.push_back(1);
            else vv.push_back(0);
        }
        if (Query(vv) == 1) {
            res.push_back(i);
            break;
        }
    }
    assert(res.size() == 2);
    dd[res[0]] = dd[res[1]] = 1;
    for (int i = 2; i < n; i++) {
        vector<int> v;
        for (int j = 0; j < n; j++) {
            if (dd[j] == 0) {
                v.push_back(j);
            }
        }
        int l = 0, r = v.size() - 2, g = v.size() - 1;
        while (l <= r) {
            int mid = (l + r) / 2;
            vector<int> vv(n, 0);
            for (int j = 0; j <= mid; j++) vv[v[j]] = 1;
            for (int j = 0; j < res.size(); j++) vv[res[j]] = 1;
            int h = Query(vv);
            vv[res.back()] = 0;
            int k = Query(vv);
            if (h != k) {
                g = mid;
                r = mid - 1;
            }
            else l = mid + 1;
        }
        res.push_back(v[g]);
        dd[v[g]] = 1;
    }
    for (int &w : res) w++;
    Answer(res);
}
/*int main() {
    Solve(5);
}*/

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:62:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             for (int j = 0; j < res.size(); j++) vv[res[j]] = 1;
      |                             ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 344 KB # of queries: 2367
2 Correct 23 ms 344 KB # of queries: 2570
3 Correct 25 ms 344 KB # of queries: 2668
4 Correct 26 ms 344 KB # of queries: 2740
5 Correct 29 ms 344 KB # of queries: 2600
6 Correct 26 ms 344 KB # of queries: 2726
7 Correct 29 ms 344 KB # of queries: 2708
8 Correct 26 ms 344 KB # of queries: 2575
9 Correct 25 ms 344 KB # of queries: 2662
10 Correct 14 ms 344 KB # of queries: 1534
11 Correct 0 ms 344 KB # of queries: 0
12 Correct 0 ms 344 KB # of queries: 2
13 Correct 0 ms 344 KB # of queries: 3
14 Correct 0 ms 344 KB # of queries: 5
15 Correct 2 ms 344 KB # of queries: 79
16 Correct 2 ms 344 KB # of queries: 192
# Verdict Execution time Memory Grader output
1 Correct 17 ms 344 KB # of queries: 2367
2 Correct 23 ms 344 KB # of queries: 2570
3 Correct 25 ms 344 KB # of queries: 2668
4 Correct 26 ms 344 KB # of queries: 2740
5 Correct 29 ms 344 KB # of queries: 2600
6 Correct 26 ms 344 KB # of queries: 2726
7 Correct 29 ms 344 KB # of queries: 2708
8 Correct 26 ms 344 KB # of queries: 2575
9 Correct 25 ms 344 KB # of queries: 2662
10 Correct 14 ms 344 KB # of queries: 1534
11 Correct 0 ms 344 KB # of queries: 0
12 Correct 0 ms 344 KB # of queries: 2
13 Correct 0 ms 344 KB # of queries: 3
14 Correct 0 ms 344 KB # of queries: 5
15 Correct 2 ms 344 KB # of queries: 79
16 Correct 2 ms 344 KB # of queries: 192
17 Correct 222 ms 436 KB # of queries: 18495
18 Correct 211 ms 428 KB # of queries: 18249
19 Correct 209 ms 684 KB # of queries: 17590
20 Correct 201 ms 428 KB # of queries: 17148
21 Correct 205 ms 344 KB # of queries: 16194
22 Correct 216 ms 432 KB # of queries: 18259
23 Correct 219 ms 432 KB # of queries: 18188
24 Correct 88 ms 428 KB # of queries: 8235
25 Correct 202 ms 592 KB # of queries: 17736
26 Correct 207 ms 424 KB # of queries: 16233
27 Correct 86 ms 344 KB # of queries: 8526
28 Correct 162 ms 432 KB # of queries: 15940
29 Correct 182 ms 688 KB # of queries: 15922
30 Correct 200 ms 428 KB # of queries: 15940