結果

問題 No.1710 Minimum OR is X
ユーザー uytvccuytvcc
提出日時 2021-10-16 11:58:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 2,361 bytes
コンパイル時間 1,610 ms
コンパイル使用メモリ 172,468 KB
実行使用メモリ 15,908 KB
最終ジャッジ日時 2023-10-17 22:07:23
合計ジャッジ時間 5,147 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
15,584 KB
testcase_01 AC 40 ms
15,588 KB
testcase_02 AC 48 ms
15,644 KB
testcase_03 AC 40 ms
15,584 KB
testcase_04 AC 40 ms
15,584 KB
testcase_05 AC 39 ms
15,584 KB
testcase_06 AC 40 ms
15,584 KB
testcase_07 AC 41 ms
15,584 KB
testcase_08 AC 57 ms
15,844 KB
testcase_09 AC 57 ms
15,820 KB
testcase_10 AC 64 ms
15,856 KB
testcase_11 AC 52 ms
15,840 KB
testcase_12 AC 80 ms
15,800 KB
testcase_13 AC 63 ms
15,888 KB
testcase_14 AC 70 ms
15,828 KB
testcase_15 AC 46 ms
15,788 KB
testcase_16 AC 77 ms
15,864 KB
testcase_17 AC 44 ms
15,764 KB
testcase_18 AC 141 ms
15,908 KB
testcase_19 AC 93 ms
15,908 KB
testcase_20 AC 44 ms
15,908 KB
testcase_21 AC 163 ms
15,908 KB
testcase_22 AC 192 ms
15,908 KB
testcase_23 AC 40 ms
15,736 KB
testcase_24 AC 40 ms
15,640 KB
testcase_25 AC 40 ms
15,704 KB
testcase_26 AC 40 ms
15,840 KB
testcase_27 AC 39 ms
15,724 KB
testcase_28 AC 51 ms
15,884 KB
testcase_29 AC 39 ms
15,740 KB
testcase_30 AC 40 ms
15,616 KB
testcase_31 AC 40 ms
15,688 KB
testcase_32 AC 51 ms
15,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF 1000000007
#define LINF 1000000000000000007LL
#define PI 3.14159265359
#define P pair<ll,ll>
template <typename T>
inline bool chmax(T &a, const T &b){
  if(a<b) {a=b; return true;}
  else return false;
}
template <typename T>
inline bool chmin(T &a, const T &b){
  if(a>b) {a=b; return true;}
  else return false;
}
struct Edge{
  int to; ll cost;
  Edge(int to, ll cost) : to(to), cost(cost) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g,int from,int to,ll cost,bool rev,ll rev_cost){
  g[from].push_back(Edge(to,cost));
  if(rev) g[to].push_back(Edge(from,rev_cost));
}

//xのn乗
ll mod_pow(ll x, ll n, ll m) {// O(log(n))
    ll res = 1;
    while (n > 0) {//繰り返し二乗法
        if (n & 1) res = res * x % m;
        x = x * x % m;
        n >>= 1;
    }
    return res;
}

const int MAX = 510000; // 5*(10^5)

ll fac[MAX], finv[MAX], inv[MAX];

void init_nCk(int m) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % m;
        inv[i] = m - inv[m%i] * (m / i) % m;
        finv[i] = finv[i - 1] * inv[i] % m;
    }
}

ll nCk(int n, int k,int m){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % m) % m;
}

ll nPk(int n, int k, int m){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n]*finv[n-k]%m;
}

ll dp[210][210];

void solve(){
  init_nCk(MOD2);
  int n,m,k;
  string x;
  cin>>n>>m>>k>>x;
  dp[0][n]=1;
  rep(b,m){
    for(int j=n; j>=k; j--){
      if(x[b]=='0'){
        for(int i=0; i<=n-k; i++){
          dp[b+1][j] += dp[b][j+i]*nCk(j+i,i,MOD2)%MOD2*mod_pow(2,(m-b-1)*i,MOD2)%MOD2;
          dp[b+1][j]%=MOD2;
        }
      }
      if(x[b]=='1'){
        for(int i=0; i<=k-1; i++){
          dp[b+1][j] += dp[b][j] * nCk(j,i,MOD2) %MOD2;
          dp[b+1][j] %=MOD2;
        }
      }
    }
  }
  ll ans=0;
  for(int j=n; j>=k; j--){
    ans += dp[m][j];
    ans %=MOD2;
  }
  cout<<ans<<'\n';
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<setprecision(10)<<fixed;
  solve();
  return 0;
}
0