답안 #45549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45549 2018-04-15T10:13:47 Z Extazy 도서관 (JOI18_library) C++17
100 / 100
550 ms 880 KB
#include <bits/stdc++.h>
#include "library.h"
#ifdef skeleta
    #include "grader.cpp"
#endif

using namespace std;

const int MAXN = 1007;

int n;
vector < int > qry;
int edges_count;
vector < int > v[MAXN];
bool used[MAXN];
vector < pair < int, int > > edges;

int count_them(int l, int r) {
    int i,ans=0;

    for(i=0;i<(int)(edges.size());i++) {
        if(l<=edges[i].first && edges[i].second<=r) {
            ++ans;
        }
    }

    return ans;
}

int ask(int l, int r) { //Returns the number of new connections amont books with numbers l, l+1, ..., r
    int i;
    
    for(i=0;i<n;i++) qry[i]=0;
    for(i=l;i<=r;i++) qry[i-1]=1;
    return r-l+1-Query(qry)-count_them(l,r);
}

void add_edge(int x, int y) {
    ++edges_count;
    edges.push_back(make_pair(min(x,y),max(x,y)));
    v[x].push_back(y);
    v[y].push_back(x);
}

void return_answer() {
    int i;
    vector < int > ans;
    queue < int > q;

    for(i=1;i<=n;i++) if(v[i].size()==1) {
        used[i]=true;
        q.push(i);
        break;
    }

    while(!q.empty()) {
        int curr=q.front();
        q.pop();
        ans.push_back(curr);

        for(i=0;i<(int)(v[curr].size());i++) if(!used[v[curr][i]]) {
            used[v[curr][i]]=true;
            q.push(v[curr][i]);
        }
    }

    Answer(ans);
}

void Solve(int NN) {
    int i,last=0;
    n=NN;

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

    qry.assign(n,0);

    while(edges_count<n-1) {
        int qans,left=last,right=n,middle;
        
        while(right-left>1) {
            middle=(left+right)>>1;
            qans=ask(1,middle);
            if(qans>0) right=middle;
            else left=middle;
        }

        last=right;
        
        left=1;
        right=last;

        while(right-left>1) {
            middle=(left+right)>>1;
            qans=ask(middle,last);
            if(qans>0) left=middle;
            else right=middle;
        }

        add_edge(left,last);

        --last;
    }

    return_answer();
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:71:9: warning: unused variable 'i' [-Wunused-variable]
     int i,last=0;
         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 376 KB Output is correct
2 Correct 42 ms 376 KB Output is correct
3 Correct 40 ms 484 KB Output is correct
4 Correct 40 ms 484 KB Output is correct
5 Correct 40 ms 516 KB Output is correct
6 Correct 41 ms 544 KB Output is correct
7 Correct 45 ms 544 KB Output is correct
8 Correct 43 ms 564 KB Output is correct
9 Correct 28 ms 564 KB Output is correct
10 Correct 21 ms 688 KB Output is correct
11 Correct 1 ms 688 KB Output is correct
12 Correct 2 ms 688 KB Output is correct
13 Correct 2 ms 688 KB Output is correct
14 Correct 2 ms 688 KB Output is correct
15 Correct 2 ms 688 KB Output is correct
16 Correct 4 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 376 KB Output is correct
2 Correct 42 ms 376 KB Output is correct
3 Correct 40 ms 484 KB Output is correct
4 Correct 40 ms 484 KB Output is correct
5 Correct 40 ms 516 KB Output is correct
6 Correct 41 ms 544 KB Output is correct
7 Correct 45 ms 544 KB Output is correct
8 Correct 43 ms 564 KB Output is correct
9 Correct 28 ms 564 KB Output is correct
10 Correct 21 ms 688 KB Output is correct
11 Correct 1 ms 688 KB Output is correct
12 Correct 2 ms 688 KB Output is correct
13 Correct 2 ms 688 KB Output is correct
14 Correct 2 ms 688 KB Output is correct
15 Correct 2 ms 688 KB Output is correct
16 Correct 4 ms 688 KB Output is correct
17 Correct 456 ms 880 KB Output is correct
18 Correct 440 ms 880 KB Output is correct
19 Correct 453 ms 880 KB Output is correct
20 Correct 480 ms 880 KB Output is correct
21 Correct 402 ms 880 KB Output is correct
22 Correct 458 ms 880 KB Output is correct
23 Correct 445 ms 880 KB Output is correct
24 Correct 206 ms 880 KB Output is correct
25 Correct 460 ms 880 KB Output is correct
26 Correct 420 ms 880 KB Output is correct
27 Correct 167 ms 880 KB Output is correct
28 Correct 550 ms 880 KB Output is correct
29 Correct 542 ms 880 KB Output is correct
30 Correct 544 ms 880 KB Output is correct