提出 #70716720


ソースコード 拡げる

// Counting Template
#include<bits/stdc++.h>

using namespace std;

const long long mod=998244353;
const long long 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;
}

using ll=long long;

long long solve(){
  // write your code here, and return the answer
  long long d,n;
  cin >> d >> n;
  if(d>n){return 0;}
  n-=d;
  ll res=0;
  for(ll t2=0;t2<=n;t2++){
    ll t3=n-2*t2;
    if(t3<0 || t3%3!=0){continue;}
    t3/=3;
    ll del=calcnCr(d,t2);
    del*=calcnCr(d,t3);
    res+=del; res%=mod;
  }
  return res;
}

int main(){
  cfact();
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t=1;
  // cin >> t;
  while(t>0){
    t--;
    cout << solve()%mod << "\n";
  }
  return 0;
}

提出情報

提出日時
問題 A - お菓子
ユーザ physics0523
言語 C++ 20 (gcc 12.2)
得点 2
コード長 1472 Byte
結果 AC
実行時間 16 ms
メモリ 19884 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 2 / 2
結果
AC × 2
AC × 6
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 02_corner_00.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 15 ms 19724 KiB
00_sample_01.txt AC 16 ms 19884 KiB
01_random_00.txt AC 15 ms 19784 KiB
01_random_01.txt AC 16 ms 19816 KiB
01_random_02.txt AC 16 ms 19880 KiB
02_corner_00.txt AC 16 ms 19816 KiB