Submission #1367731

#TimeUsernameProblemLanguageResultExecution timeMemory
1367731mikolaj00A Difficult(y) Choice (BOI21_books)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

// ll skim(int i)
// {
//     return 0LL;
// }

// void answer(vector<int> v) {}

// void impossible() {}

int bin_search(int n, ll a)
{
    int l = 1, r = n;
    while (l < r)
    {
        int mid = (l+r+1)>>1;
        if (skim(mid) <= a)
            l = mid;
        else
            r = mid-1;
    }
    return l;
}

bool try_books(vector<pair<ll, int>> books, ll a)
{
    ll s = 0LL;
    for (auto[val, idx] : books)
        s += val;

    if (a <= s && s <= 2LL*a)
    {
        vector<int> ans(books.size());
        for (int i = 0; i < books.size(); i++)
            ans[i] = books[i].second;
        answer(ans);
        return true;
    }
    
    return false;
}

void solve(int n, int k, ll a, int s)
{
    vector<pair<ll, int>> skimmed;
    int q = bin_search(n, a);
    if (q < k)
    {
        impossible();
        return;
    }
    else if (q < 2*k)
    {
        for (int i = 1; i <= q; i++)
            skimmed.push_back({skim(i), i});
    }
    else
    {
        for (int i = 1; i <= k; i++)
            skimmed.push_back({skim(i), i});
        for (int i = q-k+1; i <= q; i++)
            skimmed.push_back({skim(i), i});
    }

    if (q+1 <= n)
    {
        vector<pair<ll, int>> books;
        for (int i = 0; i < k-1; i++)
            books.push_back(skimmed[i]);
        books.push_back({skim(q+1), q+1});
        
        if (try_books(books, a))
            return;
    }

    for (int i = 0; i+k-1 <= q; i++)
    {
        vector<pair<ll, int>> books;
        for (int j = i; j < i+k; j++)
            books.push_back(skimmed[j]);

        if (try_books(books, a))
            return;
    }

    impossible();
}

Compilation message (stderr)

books.cpp: In function 'int bin_search(int, ll)':
books.cpp:20:13: error: 'skim' was not declared in this scope
   20 |         if (skim(mid) <= a)
      |             ^~~~
books.cpp: In function 'bool try_books(std::vector<std::pair<long long int, int> >, ll)':
books.cpp:39:9: error: 'answer' was not declared in this scope
   39 |         answer(ans);
      |         ^~~~~~
books.cpp: In function 'void solve(int, int, ll, int)':
books.cpp:52:9: error: 'impossible' was not declared in this scope
   52 |         impossible();
      |         ^~~~~~~~~~
books.cpp:58:32: error: 'skim' was not declared in this scope
   58 |             skimmed.push_back({skim(i), i});
      |                                ^~~~
books.cpp:58:30: error: no matching function for call to 'std::vector<std::pair<long long int, int> >::push_back(<brace-enclosed initializer list>)'
   58 |             skimmed.push_back({skim(i), i});
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
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,
                 from books.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; value_type = std::pair<long long int, int>]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<long long int, int> >::value_type&' {aka 'const std::pair<long long int, int>&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; value_type = std::pair<long long int, int>]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, int> >::value_type&&' {aka 'std::pair<long long int, int>&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
books.cpp:63:32: error: 'skim' was not declared in this scope
   63 |             skimmed.push_back({skim(i), i});
      |                                ^~~~
books.cpp:63:30: error: no matching function for call to 'std::vector<std::pair<long long int, int> >::push_back(<brace-enclosed initializer list>)'
   63 |             skimmed.push_back({skim(i), i});
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; value_type = std::pair<long long int, int>]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<long long int, int> >::value_type&' {aka 'const std::pair<long long int, int>&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; value_type = std::pair<long long int, int>]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, int> >::value_type&&' {aka 'std::pair<long long int, int>&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
books.cpp:65:32: error: 'skim' was not declared in this scope
   65 |             skimmed.push_back({skim(i), i});
      |                                ^~~~
books.cpp:65:30: error: no matching function for call to 'std::vector<std::pair<long long int, int> >::push_back(<brace-enclosed initializer list>)'
   65 |             skimmed.push_back({skim(i), i});
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; value_type = std::pair<long long int, int>]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<long long int, int> >::value_type&' {aka 'const std::pair<long long int, int>&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; value_type = std::pair<long long int, int>]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, int> >::value_type&&' {aka 'std::pair<long long int, int>&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
books.cpp:73:26: error: 'skim' was not declared in this scope
   73 |         books.push_back({skim(q+1), q+1});
      |                          ^~~~
books.cpp:73:24: error: no matching function for call to 'std::vector<std::pair<long long int, int> >::push_back(<brace-enclosed initializer list>)'
   73 |         books.push_back({skim(q+1), q+1});
      |         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; value_type = std::pair<long long int, int>]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<long long int, int> >::value_type&' {aka 'const std::pair<long long int, int>&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; value_type = std::pair<long long int, int>]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, int> >::value_type&&' {aka 'std::pair<long long int, int>&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
books.cpp:89:5: error: 'impossible' was not declared in this scope
   89 |     impossible();
      |     ^~~~~~~~~~