結果

問題 No.1189 Sum is XOR
ユーザー auauaauaua
提出日時 2020-08-22 15:25:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,903 bytes
コンパイル時間 1,778 ms
コンパイル使用メモリ 170,544 KB
実行使用メモリ 11,240 KB
最終ジャッジ日時 2024-04-23 09:44:44
合計ジャッジ時間 3,732 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 32 ms
7,040 KB
testcase_04 AC 29 ms
6,656 KB
testcase_05 AC 46 ms
8,704 KB
testcase_06 AC 61 ms
11,136 KB
testcase_07 AC 37 ms
7,680 KB
testcase_08 AC 16 ms
5,376 KB
testcase_09 AC 16 ms
5,376 KB
testcase_10 AC 13 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=998244353;
const int MAX=200010;

//Union-Find木


int siz[MAX];
int par[MAX];
int depth[MAX];
void init(int n){
  for(int i=0;i<=n;i++){
      par[i]=i;
      depth[i]=0;
  }
  rep(i,n+1){
      siz[i]=1;
  }
}
int root(int x){
  return par[x]==x?x:par[x]=root(par[x]);
}
bool same(int x,int y){
  return root(x)==root(y);
}
void unite(int x,int y){
  x=root(x);
  y=root(y);
  ll sx=siz[x];
  ll sy=siz[y];
  if(x==y)return;
  if(depth[x]<depth[y]){
      par[x]=y;
  }else{
      par[y]=x;
      if(depth[x]==depth[y])depth[x]++;
  }
  siz[root(x)]=sx+sy;
}

signed main(){
    ll n,k;cin>>n>>k;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    init(n);
    rep(j,10){
        ll la=-1;
        rep(i,n){
            if(a[i]&(1LL<<j)){
                if(la==-1)la=i;
                else unite(i,la);
            }
        }
    }
    vector<ll>used(n);
    ll cnt=0;
    vector<ll>b(0);
    rep(i,n){
        if(used[root(i)])continue;
        used[root(i)]=1;
        cnt++;
        b.pb(siz[root(i)]);
    }
    if(cnt<k){
        cout<<0<<endl;
        return 0;
    }
    vector<vector<ll> >dp(cnt+1,vector<ll>(k+1));
    dp[0][0]=1;
    rep(i,cnt){
        rep(j,k+1){
            dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
            if(j<k){
                dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j]*b[i]%mod)%mod;
            }
        }
    }
    cout<<dp[cnt][k]<<endl;
}
0