結果
| 問題 |
No.2383 Naphthol
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-14 22:47:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 1,418 bytes |
| コンパイル時間 | 1,748 ms |
| コンパイル使用メモリ | 193,148 KB |
| 最終ジャッジ日時 | 2025-02-15 14:26:22 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#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%2==0){
ans+=modcomb(N+2,K/2);
}
}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';
}