結果

問題 No.2383 Naphthol
ユーザー butsurizukibutsurizuki
提出日時 2023-07-14 22:08:07
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 2,520 bytes
コンパイル時間 2,653 ms
コンパイル使用メモリ 244,660 KB
実行使用メモリ 19,860 KB
最終ジャッジ日時 2023-10-14 12:20:52
合計ジャッジ時間 4,005 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
19,760 KB
testcase_01 AC 14 ms
19,652 KB
testcase_02 AC 17 ms
19,724 KB
testcase_03 AC 15 ms
19,728 KB
testcase_04 AC 15 ms
19,708 KB
testcase_05 AC 15 ms
19,856 KB
testcase_06 AC 15 ms
19,756 KB
testcase_07 AC 14 ms
19,724 KB
testcase_08 AC 15 ms
19,716 KB
testcase_09 AC 14 ms
19,712 KB
testcase_10 AC 13 ms
19,844 KB
testcase_11 AC 15 ms
19,784 KB
testcase_12 AC 14 ms
19,768 KB
testcase_13 AC 15 ms
19,704 KB
testcase_14 AC 14 ms
19,836 KB
testcase_15 AC 13 ms
19,760 KB
testcase_16 AC 14 ms
19,708 KB
testcase_17 AC 15 ms
19,860 KB
testcase_18 AC 15 ms
19,712 KB
testcase_19 AC 14 ms
19,788 KB
testcase_20 AC 16 ms
19,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
//
// string gen(int x,int n){
//   string res;
//   for(int i=0;i<n;i++){
//     if(x%2){res.push_back('1');}
//     else{res.push_back('0');}
//     x/=2;
//   }
//   return res;
// }
//
// string half(int n,string s){
//   string res;
//   for(int i=0;i<n;i++){
//     res.push_back(s[(i+(n/2))%n]);
//   }
//   return res;
// }
//
// int main(){
//   for(int n=1;n<=8;n++){
//     cout << "n = " << n << " : ";
//     set<string> st;
//     vector<int> bk(2*n+4+1,0);
//     for(int i=0;i<(1<<(2*n+4));i++){
//       string s=gen(i,2*n+4);
//       if(st.find(s)!=st.end()){continue;}
//       bk[__builtin_popcount(i)]++;
//       string hs=half(2*n+4,s);
//       st.insert(s);
//       st.insert(hs);
//       reverse(s.begin(),s.end());
//       reverse(hs.begin(),hs.end());
//       st.insert(s);
//       st.insert(hs);
//     }
//     for(auto &nx : bk){cout << nx << " ";}cout << "\n";
//   }
//   return 0;
// }

#define mod 998244353
#define FACSIZE 1048576

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[FACSIZE];
long long invfact[FACSIZE];

void cfact(){
  long long i;
  factorial[0]=1;
  factorial[1]=1;
  for(i=2;i<FACSIZE;i++){
    factorial[i]=factorial[i-1]*i;
    factorial[i]%=mod;
  }
  invfact[FACSIZE-1]=modular_inverse(factorial[FACSIZE-1]);
  for(i=FACSIZE-2;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;
}

long long A226048(long long n,long long k){
  long long res;
  if(k%2==0){
    res=calcnCr(2*n,k);
    res+=3*calcnCr(n,k/2);res%=mod;
    res*=modular_inverse(4);res%=mod;
  }
  else{
    res=calcnCr(2*n,k);
    if(n%2){
      res+=2*calcnCr(n-1,(k-1)/2);res%=mod;
    }
    res*=modular_inverse(4);res%=mod;
  }
  return res;
}

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

  long long n,k;
  cin >> n >> k;
  if(n==1){
    if(k==1){
      cout << "1\n";
    }
    if(k==2){
      cout << "3\n";
    }
    if(k==3){
      cout << "3\n";
    }
    if(k==4){
      cout << "3\n";
    }
    if(k==5){
      cout << "1\n";
    }
    if(k==6){
      cout << "1\n";
    }
    return 0;
  }
  cout << A226048(n+2,k) << "\n";
  return 0;
}
0