답안 #233503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233503 2020-05-20T18:37:55 Z DS007 도서관 (JOI18_library) C++14
0 / 100
484 ms 788 KB
#include <bits/stdc++.h>
using namespace std;
#include "library.h"
 
const int N = 1000;
vector<int> adj[N];
vector<int> m, pos, res;
vector<pair<int, bool>> v;
bool isEnd[N];
int n_;
 
void dfs(int v, int p = -1) {
    res.push_back(v + 1);
    for (int i : adj[v]) {
        if (i != p)
            dfs(i, v);
    }
}
 
int get() {
    int ans = 0;
    for (int i = 0; i < n_; i++) {
        if (adj[i].size() == 1 && !isEnd[i])
            ans = i;
    }
    return ans;
}
 
int find(int num, int l, int r) {
    if (l == r) {
        m[num] = 1;
        m[pos[l]] = 1;
        if (Query(m) == 1)
            return pos[l];
        else
            return -1;
    }
 
    int mid = (l + r) / 2;
    for (int i = l; i <= mid; i++)
        m[pos[i]] = 1;
 
    m[num] = 1;
    int a1 = Query(m);
    m[num] = 0;
    int a2 = Query(m);
 
    for (int i = l; i <= mid; i++)
        m[pos[i]] = 0;
 
    if (a2 < a1)
        return find(num, mid + 1, r);
    else
        return find(num, l, mid);
}
 
void Solve(int n) {
    n_ = n;
    m.resize(n, 0);
    for (int i = 0; i < n; i++)
        v.emplace_back(i, true);
 
    for (int i = 0; i < n - 1;) {
        int num = get();
        assert(num < n);
        pos.clear();
        for (auto j : v) {
            if (j.second && j.first != num)
                pos.push_back(j.first);
        }
 
        fill(m.begin(), m.end(), 0);
        int ans = find(num, 0, (int)pos.size() - 1);
        assert(ans < n);
 
        if (ans != -1)
            adj[num].push_back(ans), adj[ans].push_back(num), i++;
        else
            isEnd[num] = true;
 
        v[num].second = false;
        v[ans].second = false;
    }
 
    int end1 = -1;
    for (int i = 0; i < n; i++) {
        if (isEnd[i] || adj[i].size() == 1)
            end1 = i;
    }
 
 	assert(end1 != -1);
    dfs(end1);
    for (int i : res)
        assert(i <= n);
    Answer(res);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 384 KB # of queries: 2588
2 Correct 44 ms 504 KB # of queries: 2585
3 Correct 43 ms 400 KB # of queries: 2694
4 Correct 41 ms 380 KB # of queries: 2710
5 Correct 45 ms 376 KB # of queries: 2712
6 Correct 47 ms 384 KB # of queries: 2724
7 Correct 51 ms 384 KB # of queries: 2736
8 Correct 43 ms 384 KB # of queries: 2581
9 Correct 44 ms 504 KB # of queries: 2703
10 Correct 21 ms 400 KB # of queries: 1593
11 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Correct 4 ms 384 KB # of queries: 1
13 Correct 4 ms 384 KB # of queries: 5
14 Correct 5 ms 384 KB # of queries: 9
15 Correct 6 ms 384 KB # of queries: 86
16 Correct 7 ms 384 KB # of queries: 213
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 384 KB # of queries: 2588
2 Correct 44 ms 504 KB # of queries: 2585
3 Correct 43 ms 400 KB # of queries: 2694
4 Correct 41 ms 380 KB # of queries: 2710
5 Correct 45 ms 376 KB # of queries: 2712
6 Correct 47 ms 384 KB # of queries: 2724
7 Correct 51 ms 384 KB # of queries: 2736
8 Correct 43 ms 384 KB # of queries: 2581
9 Correct 44 ms 504 KB # of queries: 2703
10 Correct 21 ms 400 KB # of queries: 1593
11 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Correct 4 ms 384 KB # of queries: 1
13 Correct 4 ms 384 KB # of queries: 5
14 Correct 5 ms 384 KB # of queries: 9
15 Correct 6 ms 384 KB # of queries: 86
16 Correct 7 ms 384 KB # of queries: 213
17 Correct 482 ms 412 KB # of queries: 18202
18 Correct 439 ms 440 KB # of queries: 17903
19 Correct 429 ms 788 KB # of queries: 18178
20 Correct 406 ms 632 KB # of queries: 16934
21 Correct 380 ms 564 KB # of queries: 15985
22 Correct 444 ms 504 KB # of queries: 18156
23 Correct 435 ms 504 KB # of queries: 18129
24 Correct 169 ms 384 KB # of queries: 8317
25 Correct 445 ms 480 KB # of queries: 17719
26 Correct 401 ms 504 KB # of queries: 16553
27 Correct 173 ms 504 KB # of queries: 8279
28 Correct 456 ms 508 KB # of queries: 18933
29 Correct 484 ms 504 KB # of queries: 18912
30 Correct 453 ms 504 KB # of queries: 18933