답안 #679142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679142 2023-01-07T14:50:54 Z Ronin13 도서관 (JOI18_library) C++14
100 / 100
487 ms 304 KB
#include <cstdio>
#include <vector>
#include "library.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

vector <int> vec;
vector <int> def;
int n;
int get(int x){
    int l = -1, r = vec.size() - 1;
    while(l + 1 < r){
        def.assign(n, 0);
        int mid = (l + r) / 2;
        vector <int> qv;
        for(int j = 0; j <= mid; j++){
            qv.pb(vec[j]);
        }
        for(int to : qv) def[to - 1] = 1;
        int u = Query(def);
        def[x - 1] = 1;
        int v = Query(def);
        if(u == v) r = mid;
        else l = mid;

    }
    return vec[r];
}

void Solve(int N)
{
	n = N;
    if(n == 1){
        Answer({1});
        return;
    }
	for(int i = 1; i <= n; i++)
        vec.pb(i), def.pb(0);
    vector <int> ans;
    for(int i = 1; i <= n; i++){
        vector <int> qv;
        for(int j = 0; j < i - 1; j++) qv.pb(vec[j]);
        for(int j = i; j < vec.size(); j++) qv.pb(vec[j]);
        for(int to : qv)
            def[to - 1] = 1;
        int l = Query(def);
        def.assign(n, 0);
        if(l == 1){
            ans.pb(i);
            break;
        }
    }
    //cout << ans.back();
    for(int j = 1; j < n; j++){
        for(int x = 0; x < vec.size(); x++){
            if(vec[x] == ans.back()){
                int pos = x;
                while(pos < vec.size() - 1) swap(vec[pos], vec[pos + 1]), pos++;
                vec.pop_back();
                break;
            }
        }
        ans.pb(get(ans.back()));
    }
    Answer(ans);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:44:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for(int j = i; j < vec.size(); j++) qv.pb(vec[j]);
      |                        ~~^~~~~~~~~~~~
library.cpp:56:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(int x = 0; x < vec.size(); x++){
      |                        ~~^~~~~~~~~~~~
library.cpp:59:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |                 while(pos < vec.size() - 1) swap(vec[pos], vec[pos + 1]), pos++;
      |                       ~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 208 KB # of queries: 2375
2 Correct 29 ms 208 KB # of queries: 2409
3 Correct 44 ms 208 KB # of queries: 2648
4 Correct 35 ms 208 KB # of queries: 2595
5 Correct 37 ms 208 KB # of queries: 2508
6 Correct 39 ms 208 KB # of queries: 2551
7 Correct 27 ms 208 KB # of queries: 2544
8 Correct 43 ms 208 KB # of queries: 2420
9 Correct 37 ms 208 KB # of queries: 2546
10 Correct 25 ms 208 KB # of queries: 1474
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 1
13 Correct 0 ms 208 KB # of queries: 4
14 Correct 1 ms 208 KB # of queries: 7
15 Correct 1 ms 208 KB # of queries: 77
16 Correct 3 ms 208 KB # of queries: 183
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 208 KB # of queries: 2375
2 Correct 29 ms 208 KB # of queries: 2409
3 Correct 44 ms 208 KB # of queries: 2648
4 Correct 35 ms 208 KB # of queries: 2595
5 Correct 37 ms 208 KB # of queries: 2508
6 Correct 39 ms 208 KB # of queries: 2551
7 Correct 27 ms 208 KB # of queries: 2544
8 Correct 43 ms 208 KB # of queries: 2420
9 Correct 37 ms 208 KB # of queries: 2546
10 Correct 25 ms 208 KB # of queries: 1474
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 1
13 Correct 0 ms 208 KB # of queries: 4
14 Correct 1 ms 208 KB # of queries: 7
15 Correct 1 ms 208 KB # of queries: 77
16 Correct 3 ms 208 KB # of queries: 183
17 Correct 487 ms 296 KB # of queries: 17982
18 Correct 464 ms 300 KB # of queries: 17293
19 Correct 422 ms 296 KB # of queries: 17467
20 Correct 393 ms 300 KB # of queries: 16325
21 Correct 376 ms 296 KB # of queries: 15324
22 Correct 365 ms 300 KB # of queries: 17669
23 Correct 337 ms 296 KB # of queries: 17224
24 Correct 123 ms 296 KB # of queries: 7915
25 Correct 388 ms 304 KB # of queries: 17136
26 Correct 403 ms 296 KB # of queries: 15963
27 Correct 167 ms 208 KB # of queries: 8040
28 Correct 375 ms 292 KB # of queries: 15957
29 Correct 366 ms 296 KB # of queries: 15939
30 Correct 417 ms 296 KB # of queries: 15957