답안 #189079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
189079 2020-01-13T16:04:21 Z Akashi 도서관 (JOI18_library) C++14
100 / 100
747 ms 504 KB
#include "library.h"
#include <bits/stdc++.h>
using namespace std;

vector <int> p, f;
vector <int> Left, Right;

inline int exists(int st, int dr){
    for(int i = st; i <= dr ; ++i) f[p[i]] = 1;

    int val = Query(f);
    for(auto it : Left) f[it] = 1;
    for(auto it : Right) f[it] = 1;
    int val2 = Query(f);
    for(auto it : Left) f[it] = 0;
    for(auto it : Right) f[it] = 0;

    for(int i = st; i <= dr ; ++i) f[p[i]] = 0;

    int dif = val2 - val;
    if(dif <= 1) return 1;
    return 0;
}

inline int find_value(int st, int dr){
    if(st == dr) return p[st];
    int mij = (st + dr) / 2;

    if(exists(st, mij)) return find_value(st, mij);
    else return find_value(mij + 1, dr);
}

inline bool belongs(vector <int> v, int val, int n){
    vector <int> f(n);
    for(int i = 0; i < n ; ++i) f[i] = 0;

    for(auto it : v) f[it] = 1;
    f[val] = 1;

    int x = Query(f);
    if(x == 1) return 1;
    return 0;
}

void Solve(int n){
	if(n == 1){
        vector <int> ans;
        ans.push_back(1);
        Answer(ans);
        return ;
	}

	for(int i = 0; i < n ; i++) p.push_back(i), f.push_back(1);

    for(int i = 0; i < n ; ++i){
        f[i] = 0;
        if(Query(f) == 1){
            if(Left.empty()) Left.push_back(i);
            else Right.push_back(i);
            p.erase(find(p.begin(), p.end(), i));
        }
        f[i] = 1;
    }
    for(int i = 0; i < n ; ++i) f[i] = 0;

    while(!p.empty()){
        int val = find_value(0, p.size() - 1);
        if(belongs(Left, val, n)) Left.push_back(val);
        else Right.push_back(val);

        p.erase(find(p.begin(), p.end(), val));
    }

    vector <int> ans;
    for(auto it : Left) ans.push_back(it + 1);
    reverse(Right.begin(), Right.end());
    for(auto it : Right) ans.push_back(it + 1);
    Answer(ans);
}

# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 400 KB # of queries: 2744
2 Correct 68 ms 324 KB # of queries: 2708
3 Correct 57 ms 128 KB # of queries: 2896
4 Correct 72 ms 296 KB # of queries: 2874
5 Correct 57 ms 320 KB # of queries: 2882
6 Correct 87 ms 376 KB # of queries: 2890
7 Correct 69 ms 320 KB # of queries: 2894
8 Correct 84 ms 376 KB # of queries: 2760
9 Correct 40 ms 316 KB # of queries: 2876
10 Correct 25 ms 376 KB # of queries: 1702
11 Correct 2 ms 376 KB # of queries: 0
12 Correct 2 ms 248 KB # of queries: 2
13 Correct 2 ms 376 KB # of queries: 4
14 Correct 2 ms 376 KB # of queries: 8
15 Correct 3 ms 296 KB # of queries: 96
16 Correct 11 ms 504 KB # of queries: 224
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 400 KB # of queries: 2744
2 Correct 68 ms 324 KB # of queries: 2708
3 Correct 57 ms 128 KB # of queries: 2896
4 Correct 72 ms 296 KB # of queries: 2874
5 Correct 57 ms 320 KB # of queries: 2882
6 Correct 87 ms 376 KB # of queries: 2890
7 Correct 69 ms 320 KB # of queries: 2894
8 Correct 84 ms 376 KB # of queries: 2760
9 Correct 40 ms 316 KB # of queries: 2876
10 Correct 25 ms 376 KB # of queries: 1702
11 Correct 2 ms 376 KB # of queries: 0
12 Correct 2 ms 248 KB # of queries: 2
13 Correct 2 ms 376 KB # of queries: 4
14 Correct 2 ms 376 KB # of queries: 8
15 Correct 3 ms 296 KB # of queries: 96
16 Correct 11 ms 504 KB # of queries: 224
17 Correct 694 ms 424 KB # of queries: 19132
18 Correct 698 ms 424 KB # of queries: 18882
19 Correct 620 ms 460 KB # of queries: 19172
20 Correct 604 ms 456 KB # of queries: 17864
21 Correct 614 ms 408 KB # of queries: 16768
22 Correct 741 ms 452 KB # of queries: 19170
23 Correct 692 ms 328 KB # of queries: 19164
24 Correct 212 ms 328 KB # of queries: 8796
25 Correct 497 ms 464 KB # of queries: 18660
26 Correct 551 ms 456 KB # of queries: 17474
27 Correct 238 ms 424 KB # of queries: 8772
28 Correct 739 ms 428 KB # of queries: 19912
29 Correct 747 ms 456 KB # of queries: 19890
30 Correct 661 ms 336 KB # of queries: 19912