답안 #732154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
732154 2023-04-28T14:21:02 Z nguyentunglam 도서관 (JOI18_library) C++17
0 / 100
237 ms 5060 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);
//        cout << "NGU";
    }
    else if (query({tmp, r}) == 1) swap(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]);
      |             ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 348 KB # of queries: 2657
2 Correct 40 ms 348 KB # of queries: 2723
3 Correct 47 ms 584 KB # of queries: 2778
4 Correct 43 ms 336 KB # of queries: 2765
5 Correct 47 ms 332 KB # of queries: 2891
6 Correct 38 ms 336 KB # of queries: 2737
7 Correct 47 ms 348 KB # of queries: 2706
8 Correct 32 ms 328 KB # of queries: 2690
9 Correct 36 ms 332 KB # of queries: 2746
10 Correct 19 ms 208 KB # of queries: 1575
11 Runtime error 237 ms 5060 KB Execution killed with signal 13
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 348 KB # of queries: 2657
2 Correct 40 ms 348 KB # of queries: 2723
3 Correct 47 ms 584 KB # of queries: 2778
4 Correct 43 ms 336 KB # of queries: 2765
5 Correct 47 ms 332 KB # of queries: 2891
6 Correct 38 ms 336 KB # of queries: 2737
7 Correct 47 ms 348 KB # of queries: 2706
8 Correct 32 ms 328 KB # of queries: 2690
9 Correct 36 ms 332 KB # of queries: 2746
10 Correct 19 ms 208 KB # of queries: 1575
11 Runtime error 237 ms 5060 KB Execution killed with signal 13
12 Halted 0 ms 0 KB -