結果

問題 No.2058 Binary String
ユーザー butsurizukibutsurizuki
提出日時 2022-08-26 21:45:32
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,895 bytes
コンパイル時間 3,504 ms
コンパイル使用メモリ 274,628 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-21 23:47:45
合計ジャッジ時間 4,756 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
11,760 KB
testcase_01 AC 10 ms
11,648 KB
testcase_02 AC 12 ms
11,568 KB
testcase_03 AC 9 ms
11,520 KB
testcase_04 AC 10 ms
11,648 KB
testcase_05 AC 10 ms
11,772 KB
testcase_06 AC 11 ms
11,512 KB
testcase_07 AC 24 ms
11,708 KB
testcase_08 AC 12 ms
11,572 KB
testcase_09 AC 25 ms
11,520 KB
testcase_10 AC 16 ms
11,648 KB
testcase_11 AC 13 ms
11,636 KB
testcase_12 AC 17 ms
11,604 KB
testcase_13 AC 15 ms
11,648 KB
testcase_14 AC 14 ms
11,492 KB
testcase_15 AC 14 ms
11,776 KB
testcase_16 AC 15 ms
11,536 KB
testcase_17 AC 16 ms
11,776 KB
testcase_18 AC 11 ms
11,776 KB
testcase_19 AC 25 ms
11,684 KB
testcase_20 AC 23 ms
11,684 KB
testcase_21 AC 24 ms
11,776 KB
testcase_22 AC 25 ms
11,708 KB
testcase_23 AC 26 ms
11,656 KB
testcase_24 AC 26 ms
11,776 KB
testcase_25 AC 27 ms
11,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

// Wow!
// n = 2 : 1 1 0
// n = 3 : 1 2 1 0
// n = 4 : 1 3 3 1 0
// n = 5 : 1 4 6 4 1 0
// n = 6 : 1 5 10 10 5 1 0
// n = 7 : 1 6 15 20 15 6 1 0
// n = 8 : 1 7 21 35 35 21 7 1 0
// n = 9 : 1 8 28 56 70 56 28 8 1 0
// n = 10 : 1 9 36 84 126 126 84 36 9 1 0

// long long f(long long n,long long x){
//   long long res=0;
//   for(long long i=0;i<n-1;i++){
//     if(x&(1ll<<i)){
//       x^=(1ll<<i);
//       x^=(1ll<<(i+1));
//       res++;
//     }
//   }
//   return res;
// }
//
// int main(){
//   for(int n=2;;n++){
//     vector<long long> res(n+1,0);
//     for(long long i=0;i<(1ll<<n);i++){
//       if(__builtin_popcountll(i)%2){continue;}
//       res[f(n,i)]++;
//     }
//     cout << "n = " << n << " : ";
//     for(auto &nx : res){
//       cout << nx << " ";
//     }cout << "\n";
//   }
//   return 0;
// }

#define mod 998244353
long long power(long long a,long long b){
  long long x=1,y=a;
  while(b>0){
    if(b&1ll){
      x=(x*y)%mod;
    }
    y=(y*y)%mod;
    b>>=1;
  }
  return x%mod;
}

long long modular_inverse(long long n){
  return power(n,mod-2);
}

long long factorial[524288];
long long invfact[524288];

void cfact(){
  long long i;
  factorial[0]=1;
  factorial[1]=1;
  for(i=2;i<524288;i++){
    factorial[i]=factorial[i-1]*i;
    factorial[i]%=mod;
  }
  invfact[524287]=modular_inverse(factorial[524287]);
  for(i=524286;i>=0;i--){
    invfact[i]=invfact[i+1]*(i+1);
    invfact[i]%=mod;
  }
}

long long calcnCr(long long n,long long k){
  if(k<0 || n<k){return 0;}
  return (factorial[n]*((invfact[k]*invfact[n-k])%mod))%mod;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cfact();
  long long n,k;
  cin >> n >> k;
  n--;
  long long res=0;
  for(long long i=0;i<=n;i++){
    long long ce=power(i,k);
    res+=calcnCr(n,i)*ce;
    res%=mod;
  }
  cout << res << "\n";
  return 0;
}
0