Submission #732148

# Submission time Handle Problem Language Result Execution time Memory
732148 2023-04-28T14:15:00 Z nguyentunglam Library (JOI18_library) C++17
0 / 100
271 ms 4928 KB
#include<bits/stdc++.h>
#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;
const int N = 1e5 + 10;
bool taken[N];
int n;
int query(vector<int> v) {
    vector<int> ask(n);
    for(int &j : v) ask[j - 1] = 1;
    return Query(ask);
}

vector<int> operator + (vector<int> a, vector<int> b) {
    vector<int> c = a;
    for(int &j : b) c.push_back(j);
    return c;
}

int Find(vector<int> lst, int x, int y) {
    if (lst.size() == 1) return lst[0];
    vector<int> Left, Right;
    for(int i = 0; i < lst.size(); i++) {
        if (i < lst.size() / 2) Left.push_back(lst[i]);
        else Right.push_back(lst[i]);
    }
    vector<int> v1 = {x, y}, v2 = {y};
    if (query(Left + v1) + 1 == query(Left + v2)) return Find(Left, x, y);
    return Find(Right, x, y);
}

void Solve(int N)
{
    n = N;
    if (n == 1) Answer({1});
    if (n == 2) Answer({1, 2});
    int l = 1, r = n;
    for(int i = 1; i <= n; i++) if (i != l && query({l, i}) == 1) {
        r = i;
        break;
    }

    taken[l] = taken[r] = 1;
    vector<int> init;
    for(int i = 1; i <= n; i++) if (!taken[i]) init.push_back(i);
    int tmp = Find(init, l, r);
    if (query({tmp, l, r}) != 1) {
        swap(l, r);
        tmp = Find(init, l, r);
    }
    taken[tmp] = 1;
    int x, y;
    vector<int> f, g, h = {tmp, l, r};

    x = tmp; y = l;
//    cout << tmp << " " << l << " " << r << endl;
    while (1) {
        vector<int> ask;
        for(int i = 1; i <= n; i++) if (!taken[i]) ask.push_back(i);
        if (ask.empty()) break;
        int idx = Find(ask, x, y);
        if (query({idx, x, y}) != 1) break;
        y = x; x = idx;
        taken[idx] = 1;
        f.push_back(idx);
    }

    x = r; y = l;
    while (1) {
        vector<int> ask;
        for(int i = 1; i <= n; i++) if (!taken[i]) ask.push_back(i);
        if (ask.empty()) break;
        int idx = Find(ask, x, y);
        if (query({idx, x, y}) != 1) break;
        y = x; x = idx;
        taken[idx] = 1;
        g.push_back(idx);
    }

    reverse(f.begin(), f.end());
    Answer(f + h + g);
}

Compilation message

library.cpp: In function 'int Find(std::vector<int>, int, int)':
library.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i = 0; i < lst.size(); i++) {
      |                    ~~^~~~~~~~~~~~
library.cpp:25:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         if (i < lst.size() / 2) Left.push_back(lst[i]);
      |             ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 44 ms 344 KB # of queries: 2656
2 Correct 46 ms 336 KB # of queries: 2722
3 Correct 40 ms 340 KB # of queries: 2777
4 Correct 41 ms 324 KB # of queries: 2764
5 Correct 35 ms 332 KB # of queries: 2890
6 Correct 39 ms 352 KB # of queries: 2736
7 Correct 41 ms 328 KB # of queries: 2705
8 Correct 51 ms 308 KB # of queries: 2689
9 Correct 38 ms 328 KB # of queries: 2745
10 Correct 25 ms 208 KB # of queries: 1574
11 Runtime error 271 ms 4928 KB Execution killed with signal 13
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 344 KB # of queries: 2656
2 Correct 46 ms 336 KB # of queries: 2722
3 Correct 40 ms 340 KB # of queries: 2777
4 Correct 41 ms 324 KB # of queries: 2764
5 Correct 35 ms 332 KB # of queries: 2890
6 Correct 39 ms 352 KB # of queries: 2736
7 Correct 41 ms 328 KB # of queries: 2705
8 Correct 51 ms 308 KB # of queries: 2689
9 Correct 38 ms 328 KB # of queries: 2745
10 Correct 25 ms 208 KB # of queries: 1574
11 Runtime error 271 ms 4928 KB Execution killed with signal 13
12 Halted 0 ms 0 KB -