답안 #395734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395734 2021-04-28T20:08:03 Z Victor 도서관 (JOI18_library) C++17
0 / 100
29 ms 448 KB
#include "library.h"

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = b - 1; i >= (a); --i)
#define trav(a, x) for (auto& a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;

const int INF = 1000000007;

vi dummy;
int book = 0;
uset<int> queried;

int binsearch(vi books) {
    vi qvec = dummy;
    qvec[book] = 1;

    if (sz(books) == 1) {
        qvec[books[0]] = 1;
        if (Query(qvec) != 1)
            return -1;
        else
            return books[0];
    }

    int take = sz(books) >> 1;

    rep(i, 0, take) qvec[books[i]] = 1;

    int moves = Query(qvec);
    qvec[book] = 0;
    vi nbooks;

    if (Query(qvec) < moves)
        rep(i, take, sz(books)) nbooks.push_back(books[i]);
    else
        rep(i, 0, take) nbooks.push_back(books[i]);

    return binsearch(nbooks);
}

void Solve(int n) {
    dummy.resize(n);

    vi ans(n);
    int rgt[n];
    memset(rgt, -1, sizeof(rgt));

    while (book != -1 && sz(queried) + 1 != n) {
        queried.insert(book);

        vi vec;
        rep(i, 0, n) if (!queried.count(i)) vec.push_back(i);
        int next = binsearch(vec);
        assert(rgt[book]==-1&&next!=-1);

        rgt[book] = next;
        book = next;
    }

    book = 0;
    while (book != -1 && sz(queried) + 1 != n) {
        queried.insert(book);

        vi vec;
        rep(i, 0, n) if (!queried.count(i)) vec.push_back(i);
        int next = binsearch(vec);
        assert(rgt[next]==-1);
        rgt[next] = book;
        book = next;
    }

    assert(book!=-1);
    int cnt = 0;
    rep(i, 0, n) {
        assert(0<=book||book<n);
        ans[i] = book + 1;
        book = rgt[book];
    }
    
    Answer(ans);
}

Compilation message

library.cpp: In function 'int binsearch(vi)':
library.cpp:7:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define rep(i, a, b) for (int i = a; i < (b); ++i)
      |                                        ^
library.cpp:52:9: note: in expansion of macro 'rep'
   52 |         rep(i, take, sz(books)) nbooks.push_back(books[i]);
      |         ^~~
library.cpp: In function 'void Solve(int)':
library.cpp:66:42: warning: comparison of integer expressions of different signedness: 'std::unordered_set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |     while (book != -1 && sz(queried) + 1 != n) {
      |                                          ^
library.cpp:79:42: warning: comparison of integer expressions of different signedness: 'std::unordered_set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   79 |     while (book != -1 && sz(queried) + 1 != n) {
      |                                          ^
library.cpp:91:9: warning: unused variable 'cnt' [-Wunused-variable]
   91 |     int cnt = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 29 ms 448 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 29 ms 448 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -