結果

問題 No.1856 Mex Sum 2
ユーザー 蜜蜂蜜蜂
提出日時 2022-02-23 10:18:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,004 bytes
コンパイル時間 4,149 ms
コンパイル使用メモリ 228,356 KB
実行使用メモリ 46,976 KB
最終ジャッジ日時 2023-09-14 02:36:13
合計ジャッジ時間 99,708 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
15,352 KB
testcase_01 AC 17 ms
15,412 KB
testcase_02 AC 53 ms
15,456 KB
testcase_03 AC 18 ms
15,572 KB
testcase_04 AC 20 ms
15,428 KB
testcase_05 AC 19 ms
15,368 KB
testcase_06 AC 19 ms
15,364 KB
testcase_07 AC 22 ms
15,384 KB
testcase_08 AC 17 ms
15,436 KB
testcase_09 AC 18 ms
15,352 KB
testcase_10 AC 19 ms
15,448 KB
testcase_11 AC 19 ms
15,392 KB
testcase_12 AC 18 ms
15,368 KB
testcase_13 AC 18 ms
15,352 KB
testcase_14 AC 18 ms
15,444 KB
testcase_15 AC 17 ms
15,508 KB
testcase_16 AC 19 ms
15,680 KB
testcase_17 AC 34 ms
15,604 KB
testcase_18 AC 28 ms
15,480 KB
testcase_19 AC 18 ms
15,444 KB
testcase_20 AC 19 ms
15,380 KB
testcase_21 AC 18 ms
15,568 KB
testcase_22 AC 36 ms
15,480 KB
testcase_23 AC 18 ms
15,440 KB
testcase_24 AC 26 ms
15,460 KB
testcase_25 AC 35 ms
15,404 KB
testcase_26 AC 18 ms
15,560 KB
testcase_27 AC 18 ms
15,372 KB
testcase_28 AC 18 ms
15,552 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 AC 194 ms
15,812 KB
testcase_40 AC 900 ms
15,668 KB
testcase_41 AC 1,038 ms
15,620 KB
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
権限があれば一括ダウンロードができます

ソースコード

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>;
using vst = vector<string>;
using vvst = vector<vst>;

#define fi first
#define se second
#define pb push_back
#define eb emplace_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())

using mint = modint998244353;
constexpr ll mod = 998244353;

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

long long fac[MAX],finv[MAX],inv[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;
}

ll n,m;
mint ans=0;
int failed=0;
clock_t start;

mint f(vi &a){
  vi pw2(m+1);
  rep(i,0,n){
    pw2[a[i]]++;
  }
  rep(i,0,m+1){
    pw2[i]=pow_mod(2,pw2[i],mod);
  }

  mint res=0;
  mint now=pow_mod(2,n,mod);
  rep(i,1,m+2){
    now*=pw2[i-1]-1;
    now/=pw2[i-1];
    res+=now;
  }

  return res;
}

void dfs(int n,int m,vi &a){
  clock_t now=clock();
  if((double)(now-start)/CLOCKS_PER_SEC>=1.90){
    failed=1;
    return;
  }
  if(a.size()==n){
    ans+=f(a);
    return;
  }
  rep(i,0,m+1){
    a.emplace_back(i);
    dfs(n,m,a);
    a.pop_back();
  }
}

void solve1(){
  vi a={};

  dfs(n,m,a);

  assert(failed==0);

  cout<<ans.val()<<endl;
}

void solve2(){
  mint dp[min(n,m+1)+10][2*n]={};
  rep(i,0,min(n,m+1)){
    clock_t now=clock();
    if((double)(now-start)/CLOCKS_PER_SEC>=1.90){
      failed=1;
      break;
    }
    
    if(i==0){
      rep(k,0,n+1){
        // 0にk個割り当てる
        ll cm=COM(n,k);
        ll pw2=pow_mod(2,k,mod)-1;
        mint now=cm*pw2;
        dp[i][k]=now;
      }
      continue;
    }
    rep(j,0,n+1){
      now=clock();
      if((double)(now-start)/CLOCKS_PER_SEC>=1.90){
        failed=1;
        break;
      }
        
      rep(k,0,n+1){
        // 既にj個割り当てている + iにk個割り当てる
        if(j+k>n)continue;
        ll cm=COM(n-j,k);
        ll pw2=pow_mod(2,k,mod)-1;
        mint now=cm*pw2;
        dp[i][j+k]+=now*dp[i-1][j];
      }
    }
  }

  mint ans=0;
  rep(i,0,min(n,m+1)){
    rep(j,0,n+1){
      ans+=dp[i][j]*pow_mod(2*(m-i),n-j,mod);
    }
  }
  
  assert(failed==0);

  cout<<ans.val()<<endl;
}

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

  start=clock();

  COMinit();

  cin>>n>>m;

  //solve1();
  solve2();
}
0