답안 #50145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50145 2018-06-07T21:36:44 Z spencercompton 도서관 (JOI18_library) C++17
100 / 100
568 ms 716 KB
#include <cstdio>
#include <vector>
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
int n;
vector<vector<int> > li;
vector<int> rev(vector<int> a){
    vector<int> ret;
    for(int i = a.size()-1; i>=0; i--){
        ret.push_back(a[i]);
    }
    return ret;
}
void join(int a, int b){
    vector<vector<int> > nex;
    for(int i = 0; i<li.size(); i++){
        if(i==a || i==b){
            continue;
        }
        nex.push_back(li[i]);
    }
    for(int i = 0; i<li[b].size(); i++){
        li[a].push_back(li[b][i]);
    }
    nex.push_back(li[a]);
    li = nex;
}
bool get(int a, int b){
    vector<int> use;
    use.resize(n);
    for(int i = a; i<=b; i++){
        for(int j = 0; j<li[i].size(); j++){
            use[li[i][j]] = 1;
        }
    }
    return Query(use)!=(b-a+1);
}
bool get2(int val, int loc){
    vector<int> use;
    use.resize(n);
    use[val] = 1;
    for(int i = 0; i<li[loc].size(); i++){
        use[li[loc][i]] = 1;
    }
    return Query(use)==1;
}
void Solve(int N)
{
    n = N;
// 	vector<int> M(N);
// 	int A = Query(M);
// 	vector<int> res(N);
//     Answer(res);
    for(int i =0; i<N; i++){
        vector<int> x;
        x.push_back(i);
        li.push_back(x);
    }
    while(li.size()>1){
        int low = 1;
        int high = li.size()-1;
        while(low<high){
            int mid = (low+high)/2;
            if(get(0,mid)){
                high = mid;
            }
            else{
                low = mid+1;
            }
        }
        int r = low;
        low = 0;
        high = r-1;
        while(low<high){
            int mid = (low+high+1)/2;
            if(get(mid,r)){
                low = mid;
            }
            else{
                high = mid-1;
            }
        }
        int l = low;
        bool leftFirst = get2(li[l][li[l].size()-1],r);
        if(leftFirst){
            bool needRev = get2(li[r][li[r].size()-1],l);
            if(needRev){
                li[r] = rev(li[r]);
            }
            join(l,r);
        }
        else{
            bool needRev = get2(li[r][0],l);
            if(needRev){
                li[r] = rev(li[r]);
            }
            join(r,l);
        }
    }
    vector<int> ans;
    for(int i = 0; i<li[0].size(); i++){
        ans.push_back(li[0][i]+1);
    }
    Answer(ans);
}

Compilation message

library.cpp: In function 'void join(int, int)':
library.cpp:17:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i<li.size(); i++){
                    ~^~~~~~~~~~
library.cpp:23:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i<li[b].size(); i++){
                    ~^~~~~~~~~~~~~
library.cpp: In function 'bool get(int, int)':
library.cpp:33:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j<li[i].size(); j++){
                        ~^~~~~~~~~~~~~
library.cpp: In function 'bool get2(int, int)':
library.cpp:43:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i<li[loc].size(); i++){
                    ~^~~~~~~~~~~~~~~
library.cpp: In function 'void Solve(int)':
library.cpp:102:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i<li[0].size(); i++){
                    ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 248 KB Output is correct
2 Correct 38 ms 436 KB Output is correct
3 Correct 40 ms 436 KB Output is correct
4 Correct 41 ms 436 KB Output is correct
5 Correct 33 ms 480 KB Output is correct
6 Correct 46 ms 480 KB Output is correct
7 Correct 75 ms 480 KB Output is correct
8 Correct 49 ms 532 KB Output is correct
9 Correct 47 ms 532 KB Output is correct
10 Correct 22 ms 532 KB Output is correct
11 Correct 2 ms 532 KB Output is correct
12 Correct 2 ms 532 KB Output is correct
13 Correct 2 ms 532 KB Output is correct
14 Correct 2 ms 544 KB Output is correct
15 Correct 3 ms 544 KB Output is correct
16 Correct 4 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 248 KB Output is correct
2 Correct 38 ms 436 KB Output is correct
3 Correct 40 ms 436 KB Output is correct
4 Correct 41 ms 436 KB Output is correct
5 Correct 33 ms 480 KB Output is correct
6 Correct 46 ms 480 KB Output is correct
7 Correct 75 ms 480 KB Output is correct
8 Correct 49 ms 532 KB Output is correct
9 Correct 47 ms 532 KB Output is correct
10 Correct 22 ms 532 KB Output is correct
11 Correct 2 ms 532 KB Output is correct
12 Correct 2 ms 532 KB Output is correct
13 Correct 2 ms 532 KB Output is correct
14 Correct 2 ms 544 KB Output is correct
15 Correct 3 ms 544 KB Output is correct
16 Correct 4 ms 544 KB Output is correct
17 Correct 568 ms 716 KB Output is correct
18 Correct 515 ms 716 KB Output is correct
19 Correct 467 ms 716 KB Output is correct
20 Correct 470 ms 716 KB Output is correct
21 Correct 390 ms 716 KB Output is correct
22 Correct 471 ms 716 KB Output is correct
23 Correct 481 ms 716 KB Output is correct
24 Correct 190 ms 716 KB Output is correct
25 Correct 539 ms 716 KB Output is correct
26 Correct 466 ms 716 KB Output is correct
27 Correct 186 ms 716 KB Output is correct
28 Correct 358 ms 716 KB Output is correct
29 Correct 360 ms 716 KB Output is correct
30 Correct 330 ms 716 KB Output is correct