結果

問題 No.2383 Naphthol
ユーザー Nzt3Nzt3
提出日時 2023-07-14 22:45:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,481 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 199,056 KB
実行使用メモリ 10,572 KB
最終ジャッジ日時 2023-10-14 13:03:04
合計ジャッジ時間 3,338 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
10,408 KB
testcase_01 AC 9 ms
10,400 KB
testcase_02 AC 8 ms
10,352 KB
testcase_03 AC 8 ms
10,408 KB
testcase_04 AC 8 ms
10,408 KB
testcase_05 AC 9 ms
10,352 KB
testcase_06 AC 8 ms
10,360 KB
testcase_07 AC 9 ms
10,348 KB
testcase_08 AC 9 ms
10,456 KB
testcase_09 AC 8 ms
10,408 KB
testcase_10 AC 9 ms
10,344 KB
testcase_11 AC 8 ms
10,404 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 9 ms
10,404 KB
testcase_15 AC 8 ms
10,348 KB
testcase_16 AC 8 ms
10,420 KB
testcase_17 AC 9 ms
10,516 KB
testcase_18 AC 8 ms
10,452 KB
testcase_19 AC 9 ms
10,480 KB
testcase_20 AC 8 ms
10,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

constexpr int mod=998244353;

void ch(ll &a,ll b){
  a=(a+b)%mod;
}
long long modpow(long long a,int n){
  long long ret=1,t=a;
  for(int i=0;i<30;i++){
    if(n>>i&1)ret=ret*t%mod;
    t=t*t%mod;
  }
  return ret;
}
ll fac[300000];
ll inv[300000];
ll invf[300000];

ll modcomb(int n,int r){
  if(r<0)return 0;
  if(n<r)return 0ll;
  return fac[n]*invf[r]%mod*invf[n-r]%mod;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,K;
  cin>>N>>K;
  fac[0]=inv[0]=invf[0]=1;
  fac[1]=inv[1]=invf[1]=1;
  for(int i=2;i<300000;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=inv[mod%i]*(mod-mod/i)%mod;
    invf[i]=invf[i-1]*inv[i]%mod;
  }
  ll ans=0;
  if(N==1){
    int ans1[7]={1,1,3,3,3,1,1};
    cout<<ans1[K]<<'\n';
    return 0;
  }
  if(N%2){
    //0
    ch(ans,modcomb(N*2+4,K));
    //左右
    if(K%2){
      ch(ans,modcomb(N+1,(K-1)/2)*2);
    }else{
      ch(ans,modcomb(N+1,K/2)+modcomb(N+1,K/2-1));
    }
    //上下
    if(K%2==0)ans+=modcomb(N+2,K/2);
    //上下左右
    if(K%4==2){
      ans+=modcomb((N+1)/2,(K-2)/4);
    }else if(K%4==0){
      ans+=modcomb((N+1)/2,K/4);
    }
  }else{
    //0
    ans+=modcomb(N*2+4,K);
    //左右
    if(K%2==0){
      ans+=modcomb(N+2,K/2);
    }
    //上下
    if(K%2==0)ans+=modcomb(N+2,K/2);
    //上下左右
    if(K%2==0){
      ans+=modcomb(N+2,K/2);
    }
  }
  ans%=mod;
  if(ans<0)ans+=mod;
  cout<<ans*748683265%mod<<'\n';
}
0