답안 #1080223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080223 2024-08-29T08:06:08 Z vjudge1 도서관 (JOI18_library) C++14
100 / 100
268 ms 700 KB
#include <cstdio>
#include <vector>
#include "library.h"
#include<bits/stdc++.h>
using namespace std;
//#define int long long
//#define endl '\n'
void Solve(int n){
    vector<vector<int>> inter;
    vector<int> m(n,0);
    int input;
    for(int i=0;i<n;i++){
        m[i]=1;
        input=Query(m);
        if(input!=i+1){
            break;
        }
        inter.push_back({i});
    }
    for(int k=inter.size();k<n;k++){
        int low=0,high=inter.size()-1;
        low--,high++;
        while(high-low>1){
            int mid=((high-low)>>1)+low;
            fill(m.begin(),m.end(),0);
            m[k]=1;
            for(int i=0;i<=mid;i++){
                for(int x:inter[i]){
                    m[x]=1;
                }
            }
            input=Query(m);
            if(input<mid+2){
                high=mid;
            }
            else{
                low=mid;
            }
        }
        if(high==inter.size()){
            inter.push_back({k});
            continue;
        }
        fill(m.begin(),m.end(),0);
        m[k]=1,m[inter[high][0]]=1;
        input=Query(m);
        if(input==1){
            inter[high].insert(inter[high].begin(),k);
        }
        else{
            inter[high].push_back(k);
        }
        int l=high;
        if(l<inter.size()-1){
            low=l+1,high=inter.size()-1;
            low--,high++;
            while(high-low>1){
                int mid=((high-low)>>1)+low;
                fill(m.begin(),m.end(),0);
                m[k]=1;
                for(int i=l+1;i<=mid;i++){
                    for(int x:inter[i]){
                        m[x]=1;
                    }
                }
                input=Query(m);
                if(input<mid-l+1){
                    high=mid;
                }
                else{
                    low=mid;
                }
            }
            if(high<inter.size()){
                fill(m.begin(),m.end(),0);
                m[k]=1;
                m[inter[high][0]]=1;
                input=Query(m);
                vector<int> temp;
                if(inter[l][0]==k){
                    if(input==1){
                        for(int i=inter[high].size()-1;i>=0;i--){
                            temp.push_back(inter[high][i]);
                        }
                        for(int x:inter[l]){
                            temp.push_back(x);
                        }
                    }
                    else{
                        for(int x:inter[high]){
                            temp.push_back(x);
                        }
                        for(int x:inter[l]){
                            temp.push_back(x);
                        }
                    }
                }
                else{
                    if(input==1){
                        for(int x:inter[l]){
                            temp.push_back(x);
                        }
                        for(int x:inter[high]){
                            temp.push_back(x);
                        }
                    }
                    else{
                        for(int x:inter[l]){
                            temp.push_back(x);
                        }
                        for(int i=inter[high].size()-1;i>=0;i--){
                            temp.push_back(inter[high][i]);
                        }
                    }
                }
                inter[high]=temp;
                auto it=inter.begin()+l;
                inter.erase(it);
            }
        }
    }
    vector<int> ans=inter[0];
    for(int i=0;i<ans.size();i++){
        ans[i]++;
    }
    Answer(ans);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:40:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         if(high==inter.size()){
      |            ~~~~^~~~~~~~~~~~~~
library.cpp:54:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         if(l<inter.size()-1){
      |            ~^~~~~~~~~~~~~~~
library.cpp:74:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             if(high<inter.size()){
      |                ~~~~^~~~~~~~~~~~~
library.cpp:123:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |     for(int i=0;i<ans.size();i++){
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 344 KB # of queries: 1642
2 Correct 15 ms 440 KB # of queries: 1616
3 Correct 24 ms 432 KB # of queries: 1746
4 Correct 27 ms 600 KB # of queries: 1757
5 Correct 17 ms 344 KB # of queries: 1750
6 Correct 17 ms 344 KB # of queries: 1746
7 Correct 19 ms 692 KB # of queries: 1742
8 Correct 15 ms 344 KB # of queries: 1650
9 Correct 17 ms 344 KB # of queries: 1766
10 Correct 13 ms 440 KB # of queries: 999
11 Correct 0 ms 344 KB # of queries: 1
12 Correct 0 ms 344 KB # of queries: 4
13 Correct 0 ms 344 KB # of queries: 6
14 Correct 1 ms 344 KB # of queries: 9
15 Correct 1 ms 344 KB # of queries: 56
16 Correct 2 ms 344 KB # of queries: 134
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 344 KB # of queries: 1642
2 Correct 15 ms 440 KB # of queries: 1616
3 Correct 24 ms 432 KB # of queries: 1746
4 Correct 27 ms 600 KB # of queries: 1757
5 Correct 17 ms 344 KB # of queries: 1750
6 Correct 17 ms 344 KB # of queries: 1746
7 Correct 19 ms 692 KB # of queries: 1742
8 Correct 15 ms 344 KB # of queries: 1650
9 Correct 17 ms 344 KB # of queries: 1766
10 Correct 13 ms 440 KB # of queries: 999
11 Correct 0 ms 344 KB # of queries: 1
12 Correct 0 ms 344 KB # of queries: 4
13 Correct 0 ms 344 KB # of queries: 6
14 Correct 1 ms 344 KB # of queries: 9
15 Correct 1 ms 344 KB # of queries: 56
16 Correct 2 ms 344 KB # of queries: 134
17 Correct 226 ms 688 KB # of queries: 12334
18 Correct 220 ms 688 KB # of queries: 12354
19 Correct 229 ms 688 KB # of queries: 12201
20 Correct 187 ms 692 KB # of queries: 11508
21 Correct 180 ms 684 KB # of queries: 10764
22 Correct 211 ms 688 KB # of queries: 12459
23 Correct 268 ms 700 KB # of queries: 12454
24 Correct 68 ms 592 KB # of queries: 5628
25 Correct 215 ms 684 KB # of queries: 12087
26 Correct 197 ms 592 KB # of queries: 11341
27 Correct 70 ms 440 KB # of queries: 5560
28 Correct 34 ms 600 KB # of queries: 2000
29 Correct 43 ms 444 KB # of queries: 1998
30 Correct 36 ms 688 KB # of queries: 2000