結果

問題 No.1958 Bit Game
ユーザー umezoumezo
提出日時 2022-05-27 22:49:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,277 bytes
コンパイル時間 2,238 ms
コンパイル使用メモリ 210,220 KB
実行使用メモリ 7,472 KB
最終ジャッジ日時 2023-10-20 20:34:41
合計ジャッジ時間 5,311 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
7,472 KB
testcase_01 AC 58 ms
7,472 KB
testcase_02 AC 58 ms
7,472 KB
testcase_03 AC 58 ms
7,472 KB
testcase_04 AC 58 ms
7,472 KB
testcase_05 AC 59 ms
7,472 KB
testcase_06 AC 58 ms
7,472 KB
testcase_07 AC 58 ms
7,472 KB
testcase_08 AC 58 ms
7,472 KB
testcase_09 AC 58 ms
7,472 KB
testcase_10 AC 13 ms
4,348 KB
testcase_11 AC 28 ms
5,096 KB
testcase_12 AC 37 ms
5,888 KB
testcase_13 AC 31 ms
5,360 KB
testcase_14 AC 27 ms
5,096 KB
testcase_15 AC 44 ms
6,416 KB
testcase_16 AC 30 ms
5,360 KB
testcase_17 AC 49 ms
6,680 KB
testcase_18 AC 49 ms
6,680 KB
testcase_19 AC 35 ms
5,624 KB
testcase_20 AC 28 ms
5,096 KB
testcase_21 AC 45 ms
6,416 KB
testcase_22 AC 13 ms
4,348 KB
testcase_23 AC 22 ms
4,832 KB
testcase_24 AC 41 ms
6,152 KB
testcase_25 AC 24 ms
4,832 KB
testcase_26 AC 28 ms
5,096 KB
testcase_27 AC 41 ms
6,152 KB
testcase_28 AC 35 ms
5,624 KB
testcase_29 AC 18 ms
4,568 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const int MOD=998244353;
vector<vector<ll>> matrixmul(ll m,vector<vector<ll>> a,vector<vector<ll>> b){
  vector<vector<ll>> c(m,vector<ll>(m,0)); //c:和の単位元
  rep(i,m) rep(j,m) rep(k,m) c[i][j]=(c[i][j]+a[i][k]*b[k][j]%MOD)%MOD;
  return c;
}

vector<vector<ll>> matrixpow(ll m,vector<vector<ll>> vec,ll n){
  vector<vector<ll>> ans(m,vector<ll>(m,0));
  rep(i,m) ans[i][i]=1; //ans:積の単位元
  while(n){
    if(n&1) ans=matrixmul(m,ans,vec);
    vec=matrixmul(m,vec,vec);
    n>>=1;
  }
  return ans;
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll n,x,y;
  cin>>n>>x>>y;
  vector<ll> A(x),B(y);
  rep(i,x) cin>>A[i];
  rep(i,y) cin>>B[i];
  
  ll t=1,ans=0;
  rep(k,18){
    ll b=0,d=0;
    rep(i,x) if(A[i]&(1LL<<k)) b++;
    rep(i,y) if(B[i]&(1LL<<k)) d++;
    ll a=x-b,c=y-d;
    vector<vector<ll>> C(2,vector<ll>(2));
    C[0][0]=((a*c%MOD+a*d%MOD)%MOD+b*c%MOD)%MOD,C[0][1]=(a*c%MOD+b*c%MOD)%MOD;
    C[1][0]=b*d%MOD,C[1][1]=(a*d%MOD+b*d%MOD)%MOD;
    vector<vector<ll>> D=matrixpow(2,C,n);
    ans=(ans+t*D[1][0]%MOD)%MOD;
    t*=2; 
  }
  cout<<ans<<endl;
    
  return 0;
}
0