結果

問題 No.1960 Guruguru Permutation
ユーザー pockynypockyny
提出日時 2022-05-29 16:24:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,102 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 69,948 KB
実行使用メモリ 6,036 KB
最終ジャッジ日時 2023-10-20 23:55:17
合計ジャッジ時間 2,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,036 KB
testcase_01 AC 6 ms
6,036 KB
testcase_02 AC 5 ms
6,036 KB
testcase_03 AC 5 ms
6,036 KB
testcase_04 AC 5 ms
6,036 KB
testcase_05 AC 5 ms
6,036 KB
testcase_06 AC 5 ms
6,036 KB
testcase_07 AC 6 ms
6,036 KB
testcase_08 AC 6 ms
6,036 KB
testcase_09 AC 6 ms
6,036 KB
testcase_10 AC 6 ms
6,036 KB
testcase_11 AC 6 ms
6,036 KB
testcase_12 AC 5 ms
6,036 KB
testcase_13 AC 6 ms
6,036 KB
testcase_14 AC 5 ms
6,036 KB
testcase_15 AC 5 ms
6,036 KB
testcase_16 AC 6 ms
6,036 KB
testcase_17 AC 6 ms
6,036 KB
testcase_18 AC 6 ms
6,036 KB
testcase_19 RE -
testcase_20 AC 6 ms
6,036 KB
testcase_21 AC 5 ms
6,036 KB
testcase_22 AC 6 ms
6,036 KB
testcase_23 RE -
testcase_24 AC 5 ms
6,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
using ll = long long;
const int MX = 100010;
ll f[MX],inv[MX],fi[MX];
constexpr ll mod = 998244353;
void solve(){
    inv[1] = 1;
    for(int i=2;i<MX;i++){
        inv[i] = mod - (mod/i)*inv[mod%i]%mod;
    }
    f[0] = fi[0] = 1;
    for(int i=1;i<MX;i++){
        f[i] = f[i-1]*i%mod;
        fi[i] = fi[i-1]*inv[i]%mod;
    }
}

ll nck(ll n, ll k){
    if(n<0 || k<0 || n<k) return 0;
    return f[n]*fi[k]%mod*fi[n-k]%mod;
}

ll pw(ll a,ll x){
    ll ret = 1;
    while(x){
        if(x&1) (ret *= a) %= mod;
        (a *= a) %= mod; x /= 2;
    }
    return ret;
}

int main(){
    int i,n,m,k; cin >> n >> m >> k;
    solve();
    if(m + k>=n){
        ll d = m + k - n;
        ll a = m - d,b = k - d;
        ll ans = 0;
        for(i=0;i<=min(a,b);i++) (ans += nck(a,i)*nck(b,i)%mod*f[i]%mod) %= mod;
        cout << ans << endl; 
    }else{
        ll ans = 0;
        for(i=0;i<=min(m,k);i++) (ans += nck(m,i)*nck(k,i)%mod*f[i]%mod) %= mod;
        ll d = m + k;
        for(i=d + 1;i<=n;i++) (ans *= i) %= mod;
        cout << ans << endl;
    }
}
0