結果

問題 No.1710 Minimum OR is X
ユーザー 蜜蜂蜜蜂
提出日時 2021-10-15 22:39:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 577 ms / 2,000 ms
コード長 2,081 bytes
コンパイル時間 4,179 ms
コンパイル使用メモリ 241,560 KB
実行使用メモリ 23,448 KB
最終ジャッジ日時 2023-10-17 20:37:30
合計ジャッジ時間 8,663 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
19,600 KB
testcase_01 AC 20 ms
19,600 KB
testcase_02 AC 51 ms
19,984 KB
testcase_03 AC 21 ms
19,600 KB
testcase_04 AC 20 ms
19,600 KB
testcase_05 AC 20 ms
19,600 KB
testcase_06 AC 21 ms
19,600 KB
testcase_07 AC 21 ms
19,600 KB
testcase_08 AC 107 ms
20,844 KB
testcase_09 AC 110 ms
20,828 KB
testcase_10 AC 150 ms
21,056 KB
testcase_11 AC 96 ms
20,580 KB
testcase_12 AC 165 ms
21,200 KB
testcase_13 AC 134 ms
21,220 KB
testcase_14 AC 147 ms
21,180 KB
testcase_15 AC 50 ms
20,212 KB
testcase_16 AC 163 ms
21,556 KB
testcase_17 AC 45 ms
20,024 KB
testcase_18 AC 429 ms
22,868 KB
testcase_19 AC 260 ms
21,888 KB
testcase_20 AC 70 ms
20,288 KB
testcase_21 AC 455 ms
23,028 KB
testcase_22 AC 577 ms
23,448 KB
testcase_23 AC 21 ms
19,636 KB
testcase_24 AC 21 ms
19,608 KB
testcase_25 AC 21 ms
19,624 KB
testcase_26 AC 21 ms
19,672 KB
testcase_27 AC 20 ms
19,628 KB
testcase_28 AC 54 ms
20,504 KB
testcase_29 AC 20 ms
19,636 KB
testcase_30 AC 20 ms
19,600 KB
testcase_31 AC 20 ms
19,616 KB
testcase_32 AC 53 ms
20,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 2.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;

#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

const int MAX=510000;
const long long MOD=998244353;

long long fac[MAX],finv[MAX],inv[MAX],pow2[MAX];

void COMinit(){
  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%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

long long COM(int n,int k){
  if(n<k) return 0;
  if(n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

constexpr ll mod = 998244353;

map<pair<int,int>,int> seen;
map<pair<int,int>,ll> value;

ll solve(int n,int m,int k,string x){
  if(x==""){
    return 1;
  }
  if(seen[{n,m}]==true){
    return value[{n,m}];
  }

  string next=x.substr(1);
  ll res=0;

  if(x[0]=='0'){
    //0 k個以上必要
    rep(i,k,n+1){
      //0をi個置く場合
      ll com=COM(n,i);
      com*=pow_mod(pow2[m-1],n-i,mod);
      com%=mod;
      com*=solve(i,m-1,k,next);
      res=(res+com)%mod;
    }
  }
  else{
    //0 k個未満必要
    rep(i,0,k){
      //0をi個置く場合
      ll com=COM(n,i);
      com*=solve(n,m-1,k,next);
      res=(res+com)%mod;
    }
  }

  seen[{n,m}]=true;
  value[{n,m}]=res;
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  COMinit();

  pow2[0]=1;
  rep(i,1,MAX){
    pow2[i]=pow2[i-1]*2;
    pow2[i]%=mod;
  }

  int n,m,k;
  cin>>n>>m>>k;
  string x;
  cin>>x;

  cout<<solve(n,m,k,x)<<endl;
}
0