Language: C++

//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

ll fac[MAXR+1],finv[MAXR+1],inv[MAXR+1];

//テーブルの作成
void COMinit() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    FOR(i,2,MAXR){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

// 二項係数の計算
ll COM(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}



ll bitcount(ll bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}


//無限ループかなあ？？？
signed main(){
    //これ書き忘れすぎ
    COMinit();
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,k,s,t;cin >> n >> k >> s >> t;
    vector<ll> b(n);REP(i,n)cin >> b[i];
    vector<ll> a;
    //i bit目を見て、s_i=1,t_i=0の時はi bit目は全ての数が1,0でなければならないので
    REP(i,n){
        bool f=true;
        REP(j,18){
            if((s>>j)&1 and (t>>j)&1){
                if(!((b[i]>>j)&1)){
                    f=false;break;
                }
            }else if(!((s>>j)&1) and !((t>>j)&1)){
                if((b[i]>>j)&1){
                    f=false;break;
                }
            }else if((s>>j)&1 and !((t>>j)&1)){
                cout<<0<<endl;return 0;
            }
        }
        if(f)a.PB(b[i]);
    }
    n=SIZE(a);
    k=min(n,k);
    //以下ではそれぞれのbitは0と1が少なくとも一つなければならない
    //余事象を考えれば、1だけ0だけのbitが少なくとも一つあったらOK
    //それぞれのbitで"0になる集合"と"1になる集合"を用意すると、3^L(L=18)にならね？→O(N×3^L)
    //いや、分割してくだけか
    //チェックするのは結局N個くらいで済む→O(N×2^L)
    
    //以下、集合はbitで表現

    //まずは、それぞれのbitで集合を分割
    //全て異なるのでsetで良い
    vector<pair<ll,ll>> bits;
    REP(i,18){
        //未定義にするな
        ll f1=0;ll f2=0;
        REP(j,n){
            if((a[j]>>i)&1){
                f1+=(1<<j);
            }else{
                f2+=(1<<j);
            }
        }
        if(f1 and f2)bits.PB(MP(f1,f2));
        else{cout<<0<endl;return 0;}
    }
    ll bits_len=SIZE(bits);//cout << bits_len << endl;
    #if 0
    REP(i,bits_len){
        for(auto j=bits[i].F.begin();j!=bits[i].F.end();j++){
            cout << *j << " ";
        }
        cout << endl;
        for(auto j=bits[i].S.begin();j!=bits[i].S.end();j++){
            cout << *j << " ";
        }
        cout << endl;
    }
    #endif
    //集合分割したのでさらに分割を行う(部分集合全列挙→bit全探索)
    //全探索して全て数え上げたもの一旦ans_subに格納
    ll ans_sub=0;

    //ここで答えでの組み合わせの前計算しておく
    //prior_calc[j][i]：jC1+jC2+…+jCiの答え(j:1~n,i:1~k)
    vector<vector<ll>> prior_calc(n,vector<ll>(k,0));
    REP(j,n){
        prior_calc[j][0]=COM(j+1,1);
        FOR(i,1,k-1){
            prior_calc[j][i]=prior_calc[j][i-1]+COM(j+1,i+1);
        }
    }
    //2^L
    //使い回す
    deque<ll> all_sets;//cout << bits_len << endl;
    FOR(i,1,(1<<bits_len)-1){
        //cout << 1 << endl;
        //そこまでで分けられた集合を集合ごとに保存
        //deque<set<ll>> all_sets;
        all_sets.PB((1<<n)-1);
        //L
        ll odd_even=0;
        REP(j,bits_len){
            if((i>>j)&1){
                odd_even+=1;
                ll s=SIZE(all_sets);
                //n
                REP(_,s){
                    //積集合をとりたい集合を書き出す
                    ll ins=*(all_sets.begin());
                    all_sets.pop_front();
                    //一時保存用の集合を用意する
                    ll f1=ins&(bits[j].F);ll f2=ins&(bits[j].S);
                    if(f1){all_sets.PB(f1);}
                    if(f2){all_sets.PB(f2);}
                }
            }
        }
        //これで完全に分割できた、あとはそれぞれの集合に対して1以上K以下の数を選ぶだけ
        //cout << 1 << endl;
        ll s=SIZE(all_sets);
        //n
        REP(_,s){
            ll now=*(all_sets.begin());
            all_sets.pop_front();
            ll s_sub=bitcount(now);
            //k→前計算で1にする
            if(odd_even%2){
                ans_sub+=prior_calc[s_sub-1][min(k,s_sub)-1];
            }else{
                ans_sub-=prior_calc[s_sub-1][min(k,s_sub)-1];
            }
        }
    }
    //cout << ans_sub << endl;
    ll ans=-ans_sub;
    FOR(i,1,k)ans+=COM(n,i);
    cout<< ans <<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:130:21: error: no match for 'operator<' (operand types are 'std::basic_ostream<char>' and '<unresolved overloaded function type>')
  130 |         else{cout<<0<endl;return 0;}
      |              ~~~~~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_pair.h:1045:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator<(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1045 |     operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1045:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'const std::pair<_T1, _T2>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:448:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  448 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:448:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'const std::reverse_iterator<_Iterator>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  493 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'const std::reverse_iterator<_Iterator>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1694 |     operator<(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'const std::move_iterator<_IteratorL>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1760 |     operator<(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'const std::move_iterator<_IteratorL>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
In file included from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from a.cc:3:
/usr/include/c++/14/string_view:673:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator<(basic_string_view<_CharT, _Traits>, basic_string_view<_CharT, _Traits>)'
  673 |     operator< (basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:673:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'std::basic_string_view<_CharT, _Traits>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
/usr/include/c++/14/string_view:680:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator<(basic_string_view<_CharT, _Traits>, __type_identity_t<basic_string_view<_CharT, _Traits> >)'
  680 |     operator< (basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:680:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'std::basic_string_view<_CharT, _Traits>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
/usr/include/c++/14/string_view:688:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator<(__type_identity_t<basic_string_view<_CharT, _Traits> >, basic_string_view<_CharT, _Traits>)'
  688 |     operator< (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:688:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   couldn't deduce template parameter '_CharT'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
/usr/include/c++/14/bits/basic_string.h:3874:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3874 |     operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3874:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
/usr/include/c++/14/bits/basic_string.h:3888:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3888 |     operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3888:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
/usr/include/c++/14/bits/basic_string.h:3901:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3901 |     operator<(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3901:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   mismatched types 'const _CharT*' and 'std::basic_ostream<char>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68:
/usr/include/c++/14/tuple:2600:5: note: candidate: 'template<class ... _TElements, class ... _UElements> constexpr bool std::operator<(const tuple<_UTypes ...>&, const tuple<_Elements ...>&)'
 2600 |     operator<(const tuple<_TElements...>& __t,
      |     ^~~~~~~~
/usr/include/c++/14/tuple:2600:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'const std::tuple<_UTypes ...>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
In file included from /usr/include/c++/14/deque:66,
                 from a.cc:6:
/usr/include/c++/14/bits/stl_deque.h:2334:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator<(const deque<_Tp, _Alloc>&, const deque<_Tp, _Alloc>&)'
 2334 |     operator<(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:2334:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'const std::deque<_Tp, _Alloc>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_vector.h:2089:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator<(const vector<_Tp, _Alloc>&, const vector<_Tp, _Alloc>&)'
 2089 |     operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:2089:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'const std::vector<_Tp, _Alloc>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
In file included from /usr/include/c++/14/functional:65:
/usr/include/c++/14/array:339:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> bool std::operator<(const array<_Tp, _Nm>&, const array<_Tp, _Nm>&)'
  339 |     operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
      |     ^~~~~~~~
/usr/include/c++/14/array:339:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'const std::array<_Tp, _Nm>'
  130 |         else{cout<<0<endl;return 0;}
      |                      ^~~~
In file included from /usr/include/c++/14/map:63,
                 from a.cc:11:
/usr/include/c++/14/bits/stl_map.h:1550:5: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const map<_Key, _Tp, _Compare, _Allocator>&, const map<_Key, _Tp, _Compare, _Allocator>&)'
 1550 |     operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:1550:5: note:   template argument deduction/substitution failed:
a.cc:130:22: note:   'std::basic_ostream<char>' is not derived from 'const std::ma