답안 #45156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45156 2018-04-11T14:44:32 Z ikura355 도서관 (JOI18_library) C++14
0 / 100
97 ms 724 KB
#include "library.h"
#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e3 + 5;

int n;
int head[maxn], good[maxn], com[maxn];
vector<int> way[maxn];
vector<int> ans;

int ask(int l, int r, int x) {
    vector<int> vec;
    for(int i=1;i<=n;i++) {
        if(i==x || (l<=i && i<=r)) vec.push_back(1);
        else vec.push_back(0);
    }
    return Query(vec);
}

int findhead(int x) {
    if(head[x]==x) return x;
    return head[x] = findhead(head[x]);
}

int solve(int l, int r) {
    for(int u=1;u<=n;u++) {
        good[u] = (l<=u && u<=r);
        head[u] = u;
        com[u] = 0;
    }
    for(int u=1;u<=n;u++) {
        if(!good[u]) continue;
        for(auto v : way[u]) {
            if(!good[v]) continue;
            head[findhead(u)] = findhead(v);
        }
    }
    for(int u=1;u<=n;u++) if(good[u]) com[head[u]] = 1;
    int res = 0;
    for(int u=1;u<=n;u++) res += com[u];
    return res;
}

void addedge(int x, int l, int r) {
    if(l>r) return ;
//    printf("ask [%d, %d] : %d = %d\n",l,r,x,ask(l,r,x));
//    printf("solve [%d, %d] : %d\n",l,r,solve(l,r));
    if(ask(l,r,x)>solve(l,r)) return ;
    if(l==r) {
//        printf("%d <-> %d\n",l,x);
        way[x].push_back(l);
        way[l].push_back(x);
        return ;
    }
    int mid = (l+r)/2;
    addedge(x,l,mid); addedge(x,mid+1,r);
}

void dfs(int u, int last) {
    ans.push_back(u);
    for(auto v : way[u]) {
        if(v==last) continue;
        dfs(v, u);
    }
}

void Solve(int N) {
    n = N;
    for(int x=2;x<=n;x++) addedge(x,1,x-1);
    for(int x=1;x<=n;x++) {
        if(way[x].size()==1) {
            dfs(x, 0);
            Answer(ans);
            return ;
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 248 KB Output is correct
2 Correct 63 ms 416 KB Output is correct
3 Correct 61 ms 416 KB Output is correct
4 Correct 61 ms 460 KB Output is correct
5 Correct 66 ms 476 KB Output is correct
6 Correct 65 ms 532 KB Output is correct
7 Correct 97 ms 724 KB Output is correct
8 Correct 64 ms 724 KB Output is correct
9 Correct 57 ms 724 KB Output is correct
10 Correct 34 ms 724 KB Output is correct
11 Incorrect 2 ms 724 KB Wrong Answer [7]
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 248 KB Output is correct
2 Correct 63 ms 416 KB Output is correct
3 Correct 61 ms 416 KB Output is correct
4 Correct 61 ms 460 KB Output is correct
5 Correct 66 ms 476 KB Output is correct
6 Correct 65 ms 532 KB Output is correct
7 Correct 97 ms 724 KB Output is correct
8 Correct 64 ms 724 KB Output is correct
9 Correct 57 ms 724 KB Output is correct
10 Correct 34 ms 724 KB Output is correct
11 Incorrect 2 ms 724 KB Wrong Answer [7]
12 Halted 0 ms 0 KB -