結果

問題 No.1710 Minimum OR is X
ユーザー 👑 NachiaNachia
提出日時 2021-06-14 21:39:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,681 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 79,996 KB
最終ジャッジ日時 2025-01-22 08:15:22
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

////////////////////////////////////////
// Problem : (WIP)
// Time Complexity : O( M N^2 )

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const ull MOD = 998244353;

ull powm(ull a, ull i){
  if(i == 0) return 1;
  ull r = powm(a*a%MOD,i/2);
  if(i % 2 == 1) r = r * a % MOD;
  return r;
}

ull solve(int N, int M, int K, vector<int> A){
  vector<ull> Pow2(N+1,1);
  for(int i=1; i<=N; i++) Pow2[i] = Pow2[i-1] * 2 % MOD;
  vector<vector<ull>> Comb(N+1,vector<ull>(N+1,0));
  rep(i,N+1){
    Comb[i][0] = Comb[i][i] = 1;
    for(int j=1; j<i; j++) Comb[i][j] = (Comb[i-1][j-1] + Comb[i-1][j]) % MOD;
  }

  vector<vector<ull>> dp(M+1,vector<ull>(N+1,0));
  dp[0][N] = 1;
  rep(m,M){
    for(int i=0; i<=N; i++) dp[m][i] = dp[m][i] * Pow2[N-i] % MOD;
    if(A[m] == 0){
      for(int from=K; from<=N; from++){
        for(int to=K; to<=from; to++){
          dp[m+1][to] = (dp[m+1][to] + dp[m][from] * Comb[from][to]) % MOD;
        }
      }
    }
    else{
      for(int from=K; from<=N; from++){
        for(int to=0; to<K; to++){
          dp[m+1][from] = (dp[m+1][from] + dp[m][from] * Comb[from][to]) % MOD;
        }
      }
    }
  }

  ull ans = 0;
  for(int k=K; k<=N; k++) ans += dp[M][k];
  ans %= MOD;
  return ans;
}


int main(){
  int N,M,K;
  vector<int> A;
  cin >> N >> M >> K;
  A.resize(M);
  rep(i,M){
    char c; cin >> c;
    A[i] = c - '0';
  }
  ull ans = solve(N,M,K,A);
  cout << ans << "\n";
  return 0;
}



struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;
0