제출 #1354204

#제출 시각아이디문제언어결과실행 시간메모리
1354204lizi14A 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) {
    long long fi=skim(1);
    long long bol=skim(N);
    if(fi>2*A){
        //cout<<"II"<<endl;
        impossible();
        
        return;
    }
    long long l=1,r=N;
    long long ans=-1;
    long long gvanca[N+1];
    long long x[N+1];
    fill(x,x+N+1,0);
    x[1]=fi;
    x[N]=bol;
    //if(bol<=A){
        while(l<=r){
           long long m=(l+r)/2;
            long long bati;
            if(x[m]==0){
                bati=skim(m);
                x[m]=bati;
            
            }
            else bati=x[m];
            if(bati>=A){
                ans=m;
                r=m-1;
            }
            else{
                l=m+1;
            }
        }
    //}
    if(ans==-1){
        
        ans=N+1;
        
        x[0]=fi;
        x[N]=bol;
        for(int i=2; i<=K; i++){
            if(x[i]!=0)continue;
            long long a=skim(i);
            x[i]=a;
        }
        
        for(int i=N-1; i>=N-K; i--){
            if(x[i]!=0)continue;
            //cout<<i<<" ";
            //cout<<i<<" "<<N-K<<endl;
            x[i]=skim(i);
            //cout << 1;
        }
        //cout<<"BATII!"<<endl;
        long long sum=0;
        for(int i=1; i<=K; i++){
            sum+=x[i];
        }
        //cout<<sum<<endl;
        if(sum>2*A){
            //cout<<"YY"<<endl;
            impossible();
            
            return;
        }
        
        if(sum>=A && sum<=2*A){
            vector<int>anss;
            for(long long i=1; i<=K; i++){
                anss.push_back(i);
            }
            //cout<<"1"<<endl;
            answer(anss);
            
            return;
        }
        
        
        
        vector<int>g;
        for(long long 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(long long j=i+1; j<=K; j++){
                    ja.push_back(j);
                }
                //cout<<2<<endl;
                answer(ja);
                
                return;
            }
            //cout<<sum<<endl;
        }
        //cout<<"$"<<endl;
        impossible();
        
        return;
    }
    else{
        // int x[N+1];
        // fill(x,x+N+1,0);
        x[0]=fi;
        x[N]=bol;
        for(long long i=2; i<=K; i++){
            if(x[i]!=0)continue;
            long long a=skim(i);
            x[i]=a;
        }
        for(long long i=ans-1; i>=ans-K; i--){
            if(x[i]!=0)continue;
            long long a=skim(i);
            x[i]=a;
        }
        long long sum=0;
        for(long long i=1; i<=K; i++){
            sum+=x[i];
        }
        if(sum>2*A){
            //cout<<"IO"<<endl;
            impossible();
            return;
        }
        if(sum>=A && sum<=2*A){
            vector<int>anss;
            for(int i=1; i<=K; i++){
                anss.push_back(i);
            }
            //cout<<3<<endl;
            answer(anss);
            
            return;
        }
        
        vector<int>g;
        for(long long 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(long long j=i+1; j<=K; j++){
                    ja.push_back(j);
                }
                //cout<<4<<endl;
                answer(ja);
                
                return;
            }
        }
        long long gag=0;
        vector<int>o;
        x[ans]=skim(ans);
        gag+=x[ans];
        //cout<<ans<<endl;
        //cout<<x[ans]<<" ";
        o.push_back(ans);
        for(long long i=1; i<=K-1; i++){
            if(x[i]!=0)continue;
            else x[i]=skim(i);
            gag+=x[i];
            o.push_back(i);
        }
        if(gag>=A && gag<=2*A){
            //cout<<5<<endl;
            answer(o);
            
            return;
        }
        //cout<<gag<<endl;
        //cout<<"?"<<endl;
        impossible();
        
        return;
    }
}

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

books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:5:18: error: 'skim' was not declared in this scope
    5 |     long long fi=skim(1);
      |                  ^~~~
books.cpp:9:9: error: 'impossible' was not declared in this scope
    9 |         impossible();
      |         ^~~~~~~~~~
books.cpp:17:5: error: 'fill' was not declared in this scope
   17 |     fill(x,x+N+1,0);
      |     ^~~~
books.cpp:17:5: 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:66:13: error: 'impossible' was not declared in this scope
   66 |             impossible();
      |             ^~~~~~~~~~
books.cpp:72:13: error: 'vector' was not declared in this scope
   72 |             vector<int>anss;
      |             ^~~~~~
books.cpp:72: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:72:20: error: expected primary-expression before 'int'
   72 |             vector<int>anss;
      |                    ^~~
books.cpp:74:17: error: 'anss' was not declared in this scope; did you mean 'ans'?
   74 |                 anss.push_back(i);
      |                 ^~~~
      |                 ans
books.cpp:77:20: error: 'anss' was not declared in this scope; did you mean 'ans'?
   77 |             answer(anss);
      |                    ^~~~
      |                    ans
books.cpp:77:13: error: 'answer' was not declared in this scope
   77 |             answer(anss);
      |             ^~~~~~
books.cpp:84:9: error: 'vector' was not declared in this scope
   84 |         vector<int>g;
      |         ^~~~~~
books.cpp:84: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:84:16: error: expected primary-expression before 'int'
   84 |         vector<int>g;
      |                ^~~
books.cpp:87:13: error: 'g' was not declared in this scope
   87 |             g.push_back(ans-K-i+1);
      |             ^
books.cpp:89:24: error: expected primary-expression before 'int'
   89 |                 vector<int>ja=g;
      |                        ^~~
books.cpp:91:21: error: 'ja' was not declared in this scope; did you mean 'j'?
   91 |                     ja.push_back(j);
      |                     ^~
      |                     j
books.cpp:94:24: error: 'ja' was not declared in this scope; did you mean 'jn'?
   94 |                 answer(ja);
      |                        ^~
      |                        jn
books.cpp:94:17: error: 'answer' was not declared in this scope
   94 |                 answer(ja);
      |                 ^~~~~~
books.cpp:101:9: error: 'impossible' was not declared in this scope
  101 |         impossible();
      |         ^~~~~~~~~~
books.cpp:126:13: error: 'impossible' was not declared in this scope
  126 |             impossible();
      |             ^~~~~~~~~~
books.cpp:130:13: error: 'vector' was not declared in this scope
  130 |             vector<int>anss;
      |             ^~~~~~
books.cpp:130: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:130:20: error: expected primary-expression before 'int'
  130 |             vector<int>anss;
      |                    ^~~
books.cpp:132:17: error: 'anss' was not declared in this scope; did you mean 'ans'?
  132 |                 anss.push_back(i);
      |                 ^~~~
      |                 ans
books.cpp:135:20: error: 'anss' was not declared in this scope; did you mean 'ans'?
  135 |             answer(anss);
      |                    ^~~~
      |                    ans
books.cpp:135:13: error: 'answer' was not declared in this scope
  135 |             answer(anss);
      |             ^~~~~~
books.cpp:140:9: error: 'vector' was not declared in this scope
  140 |         vector<int>g;
      |         ^~~~~~
books.cpp:140: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:140:16: error: expected primary-expression before 'int'
  140 |         vector<int>g;
      |                ^~~
books.cpp:143:13: error: 'g' was not declared in this scope
  143 |             g.push_back(ans-K-i+1);
      |             ^
books.cpp:145:24: error: expected primary-expression before 'int'
  145 |                 vector<int>ja=g;
      |                        ^~~
books.cpp:147:21: error: 'ja' was not declared in this scope; did you mean 'j'?
  147 |                     ja.push_back(j);
      |                     ^~
      |                     j
books.cpp:150:24: error: 'ja' was not declared in this scope; did you mean 'jn'?
  150 |                 answer(ja);
      |                        ^~
      |                        jn
books.cpp:150:17: error: 'answer' was not declared in this scope
  150 |                 answer(ja);
      |                 ^~~~~~
books.cpp:156:16: error: expected primary-expression before 'int'
  156 |         vector<int>o;
      |                ^~~
books.cpp:161:9: error: 'o' was not declared in this scope
  161 |         o.push_back(ans);
      |         ^
books.cpp:170:13: error: 'answer' was not declared in this scope
  170 |             answer(o);
      |             ^~~~~~
books.cpp:176:9: error: 'impossible' was not declared in this scope
  176 |         impossible();
      |         ^~~~~~~~~~