답안 #441574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441574 2021-07-05T11:54:37 Z blue 도서관 (JOI18_library) C++17
19 / 100
367 ms 352 KB
#include "library.h"
#include <vector>
#include <iostream>
using namespace std;

const int maxN = 1000;
int N1;

int ask_vector(vector<int> Q)
{
    vector<int> M(N1, 0);
    for(int q:Q) M[q-1] = 1;
    return Query(M);
}

vector<int> neighbors[1+maxN];

bool neighboring(int i, int j)
{
    bool flag = 0;
    for(int x: neighbors[i]) if(x == j) flag = 1;
    return flag;
}

void find_neighbors(int I, vector<int> Q)
{
    // cerr << "find_neighbors " << I << ", ";
    // for(int q:Q) cerr << q << ' ';
    // cerr << '\n';
    if(Q.size() == 0) return;
    else if(neighbors[I].size() == 2) return;
    else if(Q.size() == 1)
    {
        if(ask_vector(vector<int>{I, Q[0]}) == 1)
        {
            neighbors[I].push_back(Q[0]);
            neighbors[Q[0]].push_back(I);
        }
    }
    else
    {
        int noI = ask_vector(Q);

        Q.push_back(I);
        int withI = ask_vector(Q);

        Q.pop_back();

        if(withI == noI + 1) return;

        vector<int> Q1, Q2;
        for(int i = 0; i < Q.size()/2; i++) Q1.push_back(Q[i]);
        for(int i = Q.size()/2; i < Q.size(); i++) Q2.push_back(Q[i]);

        find_neighbors(I, Q1);
        if(neighbors[I].size() == 2) return;
        find_neighbors(I, Q2);
    }
}

void Solve(int N)
{
    N1 = N;

    for(int i = 1; i <= N; i++)
    {
        if(neighbors[i].size() == 2) continue;

        vector<int> Q;
        for(int j = 1; j <= N; j++)
        {
            if(i != j && !neighboring(i, j))
                Q.push_back(j);
        }

        find_neighbors(i, Q);
    }

















    vector<int> visit(N+1, 0);

    vector<int> res;
    for(int i = 1; i <= N; i++)
    {
        if(neighbors[i].size() <= 1)
        {
            res.push_back(i);
            visit[i] = 1;
            break;
        }
    }

    for(int i = 0; i < N; i++)
    {
        int u = res[i];
        for(int v: neighbors[u])
        {
            if(visit[v]) continue;
            visit[v] = 1;
            res.push_back(v);
        }
    }


    // for(int r:res) cerr << r << ' ';
    // cerr << '\n';


    Answer(res);
}

Compilation message

library.cpp: In function 'void find_neighbors(int, std::vector<int>)':
library.cpp:52:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int i = 0; i < Q.size()/2; i++) Q1.push_back(Q[i]);
      |                        ~~^~~~~~~~~~~~
library.cpp:53:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int i = Q.size()/2; i < Q.size(); i++) Q2.push_back(Q[i]);
      |                                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 308 KB # of queries: 4402
2 Correct 74 ms 308 KB # of queries: 4472
3 Correct 74 ms 304 KB # of queries: 4625
4 Correct 78 ms 200 KB # of queries: 4709
5 Correct 77 ms 308 KB # of queries: 4638
6 Correct 79 ms 304 KB # of queries: 4659
7 Correct 63 ms 200 KB # of queries: 4706
8 Correct 79 ms 200 KB # of queries: 4442
9 Correct 69 ms 304 KB # of queries: 4659
10 Correct 50 ms 200 KB # of queries: 2693
11 Correct 0 ms 200 KB # of queries: 0
12 Correct 0 ms 200 KB # of queries: 1
13 Correct 1 ms 200 KB # of queries: 6
14 Correct 1 ms 200 KB # of queries: 16
15 Correct 3 ms 200 KB # of queries: 164
16 Correct 6 ms 200 KB # of queries: 370
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 308 KB # of queries: 4402
2 Correct 74 ms 308 KB # of queries: 4472
3 Correct 74 ms 304 KB # of queries: 4625
4 Correct 78 ms 200 KB # of queries: 4709
5 Correct 77 ms 308 KB # of queries: 4638
6 Correct 79 ms 304 KB # of queries: 4659
7 Correct 63 ms 200 KB # of queries: 4706
8 Correct 79 ms 200 KB # of queries: 4442
9 Correct 69 ms 304 KB # of queries: 4659
10 Correct 50 ms 200 KB # of queries: 2693
11 Correct 0 ms 200 KB # of queries: 0
12 Correct 0 ms 200 KB # of queries: 1
13 Correct 1 ms 200 KB # of queries: 6
14 Correct 1 ms 200 KB # of queries: 16
15 Correct 3 ms 200 KB # of queries: 164
16 Correct 6 ms 200 KB # of queries: 370
17 Runtime error 367 ms 352 KB Execution killed with signal 13
18 Halted 0 ms 0 KB -