結果

問題 No.1691 Badugi
ユーザー chocoruskchocorusk
提出日時 2021-09-24 23:10:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 2,157 bytes
コンパイル時間 3,458 ms
コンパイル使用メモリ 189,636 KB
実行使用メモリ 19,280 KB
最終ジャッジ日時 2023-09-18 22:17:48
合計ジャッジ時間 4,900 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
18,988 KB
testcase_01 AC 17 ms
19,152 KB
testcase_02 AC 17 ms
19,012 KB
testcase_03 AC 17 ms
18,996 KB
testcase_04 AC 17 ms
18,996 KB
testcase_05 AC 16 ms
18,996 KB
testcase_06 AC 17 ms
19,088 KB
testcase_07 AC 16 ms
19,052 KB
testcase_08 AC 17 ms
19,016 KB
testcase_09 AC 17 ms
19,088 KB
testcase_10 AC 17 ms
19,052 KB
testcase_11 AC 17 ms
19,016 KB
testcase_12 AC 17 ms
18,988 KB
testcase_13 AC 17 ms
19,276 KB
testcase_14 AC 17 ms
19,020 KB
testcase_15 AC 17 ms
19,280 KB
testcase_16 AC 17 ms
19,000 KB
testcase_17 AC 17 ms
19,020 KB
testcase_18 AC 17 ms
19,044 KB
testcase_19 AC 17 ms
18,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
using mint=modint998244353;
mint f[2000010], invf[2000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i;
    invf[n]=f[n].inv();
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1);
}
mint comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]*invf[x-y];
}
int n, m, k;

int main()
{
    cin>>n>>m>>k;
    fac(1000000);
    mint ans=0;
    auto calc=[&](int n, int m, int k){
        return comb(n, k)*f[m]*invf[m-k];
    };
    ans+=n*comb(m, 3)*calc(n-1, m-3, k-3);
    ans+=m*comb(n, 3)*calc(m-1, n-3, k-3);

    if(k-2>=2)ans+=comb(n, 2)*comb(m, 2)*comb(m-2, 2)*calc(n-2, m-4, k-4);
    if(k-2>=2)ans+=comb(m, 2)*comb(n, 2)*comb(n-2, 2)*calc(m-2, n-4, k-4);

    if(k-2>=2)ans+=n*comb(m, 2)*(m-2)*comb(n-1, 2)*calc(n-3, m-3, k-4);

    if(k-2>=2)ans+=comb(n, 2)*comb(m, 3)*2*3*calc(n-2, m-3, k-4);
    if(k-2>=2)ans+=comb(m, 2)*comb(n, 3)*2*3*calc(m-2, n-3, k-4);

    if(k-2>=3)ans+=comb(n, 2)*comb(m, 2)*2*2*(n-2)*comb(m-2, 2)*calc(n-3, m-4, k-5);
    if(k-2>=3)ans+=comb(n, 2)*comb(m, 2)*2*2*(m-2)*comb(n-2, 2)*calc(m-3, n-4, k-5);

    if(k-2>=2)ans+=comb(n, 2)*comb(m, 3)*2*3*calc(n-2, m-3, k-4);
    if(k-2>=2)ans+=comb(m, 2)*comb(n, 3)*2*3*calc(m-2, n-3, k-4);

    if(k-2>=4)ans+=comb(n, 2)*comb(n-2, 2)*comb(m, 2)*comb(m-2, 2)*8*calc(n-4, m-4, k-6);

    if(k-2>=3)ans+=comb(n, 3)*comb(m, 3)*3*3*2*calc(n-3, m-3, k-5)*2;

    if(k-2>=2)ans+=comb(n, 2)*comb(m, 2)*calc(n-2, m-2, k-4);

    if(k-2>=3)ans+=comb(n, 3)*comb(m, 3)*6*6*calc(n-3, m-3, k-5);

    cout<<ans.val()<<endl;
    return 0;
}
0