Submission #70662393


Source Code Expand

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

const int MOD = 998244353;

long long modpow(long long a, long long e){
    long long r=1;
    while(e){
        if(e&1) r=r*a%MOD;
        a=a*a%MOD; e>>=1;
    }
    return r;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M,S; 
    if(!(cin>>N>>M>>S)) return 0;

    int LIM = N + S + 5;
    vector<long long> fact(LIM), invfact(LIM);
    fact[0]=1;
    for(int i=1;i<LIM;i++) fact[i]=fact[i-1]*i%MOD;
    invfact[LIM-1]=modpow(fact[LIM-1], MOD-2);
    for(int i=LIM-2;i>=0;i--) invfact[i]=invfact[i+1]*(i+1)%MOD;

    auto C = [&](int n,int r)->long long{
        if(r<0||r>n||n<0) return 0;
        return fact[n]*invfact[r]%MOD*invfact[n-r]%MOD;
    };

    long long ans=0;
    int tmax = S/(M+1);
    for(int j=0;j<=tmax;j++){
        long long ways = C(N, j) * C(S - j*(M+1) + N - 1, N - 1) % MOD;
        if(j&1) ans = (ans - ways + MOD) % MOD;
        else ans = (ans + ways) % MOD;
    }
    cout << ans << "\n";
    return 0;
}

Submission Info

Submission Time
Task C - Sequence
User blackbeen
Language C++ 20 (gcc 12.2)
Score 3
Code Size 1061 Byte
Status AC
Exec Time 7 ms
Memory 9432 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 3 / 3
Status
AC × 2
AC × 9
Set Name Test Cases
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, 02_m_small_00.txt, 02_m_small_01.txt, 02_m_small_02.txt, 03_max_00.txt, 04_min_00.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3432 KiB
00_sample_01.txt AC 3 ms 4644 KiB
01_random_00.txt AC 3 ms 5456 KiB
01_random_01.txt AC 5 ms 7836 KiB
02_m_small_00.txt AC 7 ms 9388 KiB
02_m_small_01.txt AC 7 ms 9432 KiB
02_m_small_02.txt AC 7 ms 9340 KiB
03_max_00.txt AC 6 ms 9340 KiB
04_min_00.txt AC 1 ms 3428 KiB