結果

問題 No.1856 Mex Sum 2
ユーザー 蜜蜂蜜蜂
提出日時 2022-02-23 10:17:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,744 bytes
コンパイル時間 3,101 ms
コンパイル使用メモリ 229,076 KB
実行使用メモリ 814,592 KB
最終ジャッジ日時 2023-09-14 02:31:54
合計ジャッジ時間 29,265 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
15,380 KB
testcase_01 AC 12 ms
15,508 KB
testcase_02 RE -
testcase_03 AC 15 ms
15,524 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 15 ms
15,396 KB
testcase_14 AC 13 ms
15,316 KB
testcase_15 AC 13 ms
15,388 KB
testcase_16 MLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
権限があれば一括ダウンロードができます

ソースコード

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)){
    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){
      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);
    }
  }

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

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

  start=clock();

  COMinit();

  cin>>n>>m;

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