結果

問題 No.1304 あなたは基本が何か知っていますか?私は知っています.
ユーザー fumofumofunifumofumofuni
提出日時 2020-12-01 18:08:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,417 bytes
コンパイル時間 2,630 ms
コンパイル使用メモリ 204,948 KB
最終ジャッジ日時 2025-01-16 11:54:02
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 27 TLE * 25 MLE * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=(r)-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int mod = MOD9;
const int max_n = 200005;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  bool operator==(const mint &p) const { return x == p.x; }
  bool operator!=(const mint &p) const { return x != p.x; }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[40][1024][1024];//j=末尾、k=xor;

int main(){
    ll n,k,x,y;cin >> n >> k >> x >> y;
    set<ll> st;rep(i,k){
        ll p;cin >> p;st.insert(p);
    }

    if(n==2){
        mint ans=0;
        for(auto p:st){
            for(auto q:st){
                if(p==q)continue;
                ll t=p^q;
                if(x<=t&&t<=y)ans+=1;
            }
        }
        cout << ans <<endl;
        return 0;
    }

    if(n==4){
        ll ans=0;
        /*mint ep[n+1][1024];rep(i,n+1)rep(j,1024)ep[i][j]=0;
        ep[0][0]=1;
        rep(i,4)rep(j,1024)for(auto p:st)ep[i+1][j^p]+=ep[i][j];*/
        vector<vector<ll>> store(1024,vector<ll>(1024,0));//key:xor,val[i]:要素
        vector<ll> tot(1024);//key:xor,val[i]:要素
        for(auto p:st){
            for(auto q:st){
                if(p==q)continue;
                ll t=p^q;
                store[t][q]+=1;
                tot[t]+=1;
                //if(x<=t&&t<=y)ans+=1;
            }
        }
        rep(i,1024){
            if(i<x||i>y)continue;
            rep(j,1024){
                ll com=i^j;
                if(com>j)continue;
                ll ret=0;
                ret+=tot[com]*tot[j];
                rep(z,1024)ret-=store[com][z]*store[j][z];
                if(com<j)ret*=2;
                ans+=ret;
            }
        }
        cout << ans%MOD9 <<endl;
        return 0;
        //map<ll,vl> mp;//key:xor,val[i]:要素
        //map<ll,ll> tot;//key:xor,val[i]:要素
        //rep(j,10)cout << ep[n][j] <<endl;
        /*rep(i,1024)if(x<=i&&i<=y)ans+=ep[4][i];
        rep(i,1024)if(x<=i&&i<=y)ans-=ep[2][i]*3*st.size();
        rep(i,1024)if(x<=i&&i<=y)ans+=ep[2][i]*2;
        if(x==0)ans-=st.size();
        cout << ans <<endl;*/
        return 0;
    }

    rep(i,40)rep(j,1024)rep(k,1024)dp[i][j][k]=0;
    for(auto p:st)dp[0][p][p]=1;
    rep(i,n-1){
        for(auto j:st){
            rep(k,1024){
                for(auto p:st){
                    if(j==p)continue;
                    dp[i+1][p][k^p]+=dp[i][j][k];
                }
            }
        }
    }
    mint ans=0;
    rep(j,1024)rep(k,1024){
        if(x<=k&&k<=y)ans+=dp[n-1][j][k];
    }
    cout << ans <<endl;
}
0