제출 #1354107

#제출 시각아이디문제언어결과실행 시간메모리
1354107lizi14A Difficult(y) Choice (BOI21_books)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
//#include"books.h"
//using namespace std;
void solve(int N, int K, long long A, int S) {
    int fi=skim(1);
    int bol=skim(N);
    if(fi>2*A){
        //cout<<"II"<<endl;
        impossible();
        
        return;
    }
    int l=1,r=N;
    int ans=-1;
    while(l<=r){
        int m=(l+r)/2;
        int bati=skim(m);
        if(bati>=A){
            ans=m;
            r=m-1;
        }
        else{
            l=m+1;
        }
    }
    if(ans==-1){
        ans=N;
        int x[N+1];
        fill(x,x+N+1,0);
        x[0]=fi;
        x[N]=bol;
        for(int i=2; i<=K; i++){
            int a=skim(i);
            x[i]=a;
        }
        for(int i=ans-1; i>=ans-K; i--){
            int a=skim(i);
            x[i]=a;
        }
        int sum=0;
        for(int i=1; i<=K; i++){
            sum+=x[i];
        }
        if(sum>=A && sum<=2*A){
            vector<int>anss;
            for(int i=1; i<=K; i++){
                anss.push_back(i);
            }
            answer(anss);
            //cout<<"1"<<endl;
            return;
        }
        if(sum>2*A){
            impossible();
            return;
        }
        vector<int>g;
        for(int i=1; i<=K; i++){
            sum+=abs(x[i]-x[ans-K-i+1]);
            g.push_back(ans-K-i+1);
            if(sum>=A && sum<=2*A){
                vector<int>ja=g;
                for(int j=i+1; j<=K; j++){
                    ja.push_back(j);
                }
                answer(ja);
                //cout<<2<<endl;
                return;
            }
            //cout<<sum<<endl;
        }
        impossible();
        //cout<<"$"<<endl;
        return;
    }
    else{
        int x[N+1];
        fill(x,x+N+1,0);
        x[0]=fi;
        x[N]=bol;
        for(int i=2; i<=K; i++){
            int a=skim(i);
            x[i]=a;
        }
        for(int i=ans-1; i>=ans-K; i--){
            int a=skim(i);
            x[i]=a;
        }
        int sum=0;
        for(int i=1; i<=K; i++){
            sum+=x[i];
        }
        if(sum>=A && sum<=2*A){
            vector<int>anss;
            for(int i=1; i<=K; i++){
                anss.push_back(i);
            }
            answer(anss);
            //cout<<3<<endl;
            return;
        }
        if(sum>2*A){
            impossible();
            return;
        }
        vector<int>g;
        for(int i=1; i<=K; i++){
            sum+=abs(x[i]-x[ans-K-i+1]);
            g.push_back(ans-K-i+1);
            if(sum>=A && sum<=2*A){
                vector<int>ja=g;
                for(int j=i+1; j<=K; j++){
                    ja.push_back(j);
                }
                answer(ja);
                //cout<<4<<endl;
                return;
            }
        }
        int gag=0;
        vector<int>o;
        x[ans]=skim(ans);
        gag+=x[ans];
        //cout<<ans<<endl;
        //cout<<x[ans]<<" ";
        o.push_back(ans);
        for(int i=1; i<=K-1; i++){
            gag+=x[i];
            o.push_back(i);
        }
        if(gag>=A && gag<=2*A){
            answer(o);
            cout<<4<<endl;
            return;
        }
        //cout<<gag<<endl;
        impossible();
        //cout<<"?"<<endl;
        return;
    }
}

컴파일 시 표준 에러 (stderr) 메시지

books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:5:12: error: 'skim' was not declared in this scope
    5 |     int fi=skim(1);
      |            ^~~~
books.cpp:9:9: error: 'impossible' was not declared in this scope
    9 |         impossible();
      |         ^~~~~~~~~~
books.cpp:29:9: error: 'fill' was not declared in this scope
   29 |         fill(x,x+N+1,0);
      |         ^~~~
books.cpp:29:9: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:73,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from books.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:191:1: note:   'std::fill'
  191 | fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
In file included from /usr/include/c++/13/bits/ranges_algo.h:38,
                 from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algobase.h:595:30: note:   'std::ranges::fill'
  595 |   inline constexpr __fill_fn fill{};
      |                              ^~~~
books.cpp:45:13: error: 'vector' was not declared in this scope
   45 |             vector<int>anss;
      |             ^~~~~~
books.cpp:45:13: note: suggested alternatives:
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/13/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
books.cpp:45:20: error: expected primary-expression before 'int'
   45 |             vector<int>anss;
      |                    ^~~
books.cpp:47:17: error: 'anss' was not declared in this scope; did you mean 'ans'?
   47 |                 anss.push_back(i);
      |                 ^~~~
      |                 ans
books.cpp:49:20: error: 'anss' was not declared in this scope; did you mean 'ans'?
   49 |             answer(anss);
      |                    ^~~~
      |                    ans
books.cpp:49:13: error: 'answer' was not declared in this scope
   49 |             answer(anss);
      |             ^~~~~~
books.cpp:54:13: error: 'impossible' was not declared in this scope
   54 |             impossible();
      |             ^~~~~~~~~~
books.cpp:57:9: error: 'vector' was not declared in this scope
   57 |         vector<int>g;
      |         ^~~~~~
books.cpp:57:9: note: suggested alternatives:
/usr/include/c++/13/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/13/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
books.cpp:57:16: error: expected primary-expression before 'int'
   57 |         vector<int>g;
      |                ^~~
books.cpp:60:13: error: 'g' was not declared in this scope
   60 |             g.push_back(ans-K-i+1);
      |             ^
books.cpp:62:24: error: expected primary-expression before 'int'
   62 |                 vector<int>ja=g;
      |                        ^~~
books.cpp:64:21: error: 'ja' was not declared in this scope; did you mean 'j'?
   64 |                     ja.push_back(j);
      |                     ^~
      |                     j
books.cpp:66:24: error: 'ja' was not declared in this scope; did you mean 'jn'?
   66 |                 answer(ja);
      |                        ^~
      |                        jn
books.cpp:66:17: error: 'answer' was not declared in this scope
   66 |                 answer(ja);
      |                 ^~~~~~
books.cpp:72:9: error: 'impossible' was not declared in this scope
   72 |         impossible();
      |         ^~~~~~~~~~
books.cpp:78:9: error: 'fill' was not declared in this scope
   78 |         fill(x,x+N+1,0);
      |         ^~~~
books.cpp:78:9: note: suggested alternatives:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:191:1: note:   'std::fill'
  191 | fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/13/bits/ranges_algobase.h:595:30: note:   'std::ranges::fill'
  595 |   inline constexpr __fill_fn fill{};
      |                              ^~~~
books.cpp:94:13: error: 'vector' was not declared in this scope
   94 |             vector<int>anss;
      |             ^~~~~~
books.cpp:94:13: note: suggested alternatives:
/usr/include/c++/13/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/13/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
books.cpp:94:20: error: expected primary-expression before 'int'
   94 |             vector<int>anss;
      |                    ^~~
books.cpp:96:17: error: 'anss' was not declared in this scope; did you mean 'ans'?
   96 |                 anss.push_back(i);
      |                 ^~~~
      |                 ans
books.cpp:98:20: error: 'anss' was not declared in this scope; did you mean 'ans'?
   98 |             answer(anss);
      |                    ^~~~
      |                    ans
books.cpp:98:13: error: 'answer' was not declared in this scope
   98 |             answer(anss);
      |             ^~~~~~
books.cpp:103:13: error: 'impossible' was not declared in this scope
  103 |             impossible();
      |             ^~~~~~~~~~
books.cpp:106:9: error: 'vector' was not declared in this scope
  106 |         vector<int>g;
      |         ^~~~~~
books.cpp:106:9: note: suggested alternatives:
/usr/include/c++/13/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/13/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
books.cpp:106:16: error: expected primary-expression before 'int'
  106 |         vector<int>g;
      |                ^~~
books.cpp:109:13: error: 'g' was not declared in this scope
  109 |             g.push_back(ans-K-i+1);
      |             ^
books.cpp:111:24: error: expected primary-expression before 'int'
  111 |                 vector<int>ja=g;
      |                        ^~~
books.cpp:113:21: error: 'ja' was not declared in this scope; did you mean 'j'?
  113 |                     ja.push_back(j);
      |                     ^~
      |                     j
books.cpp:115:24: error: 'ja' was not declared in this scope; did you mean 'jn'?
  115 |                 answer(ja);
      |                        ^~
      |                        jn
books.cpp:115:17: error: 'answer' was not declared in this scope
  115 |                 answer(ja);
      |                 ^~~~~~
books.cpp:121:16: error: expected primary-expression before 'int'
  121 |         vector<int>o;
      |                ^~~
books.cpp:126:9: error: 'o' was not declared in this scope
  126 |         o.push_back(ans);
      |         ^
books.cpp:132:13: error: 'answer' was not declared in this scope
  132 |             answer(o);
      |             ^~~~~~
books.cpp:133:13: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
  133 |             cout<<4<<endl;
      |             ^~~~
      |             std::cout
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:146:
/usr/include/c++/13/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
books.cpp:133:22: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
  133 |             cout<<4<<endl;
      |                      ^~~~
      |                      std::endl
In file included from /usr/include/c++/13/bits/unique_ptr.h:42,
                 from /usr/include/c++/13/memory:78,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:56:
/usr/include/c++/13/ostream:735:5: note: 'std::endl' declared here
  735 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
books.cpp:137:9: error: 'impossible' was not declared in this scope
  137 |         impossible();
      |         ^~~~~~~~~~