Submission #1182012

#TimeUsernameProblemLanguageResultExecution timeMemory
1182012FaresSTHBank (IZhO14_bank)C++20
Compilation error
0 ms0 KiB
#include "bits/stdc++.h"
using namespace std;
int n,m,a[25],b[25],f[1001],cur[1001];
unordered_map<int,bool>memo;
vector<pair<int, int>>s;
bool sol(int i,int used){
    if(i==n){
        for(int j=0;j<n;j++){
            if(cur[a[j]]<f[a[j]])return 0;
        }
        return 1;
    }
    if(memo.find((i<<20)|used)!=memo.end())return memo[(i<<20)|used];
    for(auto[sum,mask]:s){
        if((used&mask)==0&&cur[sum]<f[sum]){
            cur[sum]++;
            if(sol(i+1,used|mask))return memo[{i,used}]=1;
            cur[sum]--;
        }
    }
    return memo[{i, used}]=0;
}
int main(){
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
        f[a[i]]++;
    }
    for(int i=0;i<m;i++)cin>>b[i];
    for(int mask=0;mask<(1<<m);mask++){
        int sum=0;
        for (int j=0;j<m;j++){
            if(mask&(1<<j))sum+=b[j];
        }
        if(f[sum])s.emplace_back(sum, mask);
    }
    cout<<(sol(0,0)?"YES":"NO");
}

Compilation message (stderr)

bank.cpp: In function 'bool sol(int, int)':
bank.cpp:17:46: error: no match for 'operator[]' (operand types are 'std::unordered_map<int, bool>' and '<brace-enclosed initializer list>')
   17 |             if(sol(i+1,used|mask))return memo[{i,used}]=1;
      |                                              ^
In file included from /usr/include/c++/11/unordered_map:47,
                 from /usr/include/c++/11/functional:61,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from bank.cpp:1:
/usr/include/c++/11/bits/unordered_map.h:979:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type&) [with _Key = int; _Tp = bool; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, bool> >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type = bool; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_type = int]'
  979 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/11/bits/unordered_map.h:979:34: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const int&'}
  979 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/unordered_map.h:983:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_type&&) [with _Key = int; _Tp = bool; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, bool> >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type = bool; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_type = int]'
  983 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/11/bits/unordered_map.h:983:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::unordered_map<int, bool>::key_type&&' {aka 'int&&'}
  983 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
bank.cpp:21:16: error: no match for 'operator[]' (operand types are 'std::unordered_map<int, bool>' and '<brace-enclosed initializer list>')
   21 |     return memo[{i, used}]=0;
      |                ^
In file included from /usr/include/c++/11/unordered_map:47,
                 from /usr/include/c++/11/functional:61,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from bank.cpp:1:
/usr/include/c++/11/bits/unordered_map.h:979:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type&) [with _Key = int; _Tp = bool; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, bool> >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type = bool; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_type = int]'
  979 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/11/bits/unordered_map.h:979:34: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const int&'}
  979 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/unordered_map.h:983:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_type&&) [with _Key = int; _Tp = bool; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, bool> >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type = bool; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_type = int]'
  983 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/11/bits/unordered_map.h:983:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::unordered_map<int, bool>::key_type&&' {aka 'int&&'}
  983 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~