結果
| 問題 |
No.1691 Badugi
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2021-09-24 23:08:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 68 ms / 2,000 ms |
| コード長 | 2,946 bytes |
| コンパイル時間 | 4,629 ms |
| コンパイル使用メモリ | 258,572 KB |
| 最終ジャッジ日時 | 2025-01-24 17:43:13 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 10000000000000000
struct combi{
deque<mint> kaijou;
deque<mint> kaijou_;
combi(int n){
kaijou.push_back(1);
for(int i=1;i<=n;i++){
kaijou.push_back(kaijou[i-1]*i);
}
mint b=kaijou[n].inv();
kaijou_.push_front(b);
for(int i=1;i<=n;i++){
int k=n+1-i;
kaijou_.push_front(kaijou_[0]*k);
}
}
mint combination(int n,int r){
if(r>n)return 0;
mint a = kaijou[n]*kaijou_[r];
a *= kaijou_[n-r];
return a;
}
mint junretsu(int a,int b){
mint x = kaijou_[a]*kaijou_[b];
x *= kaijou[a+b];
return x;
}
mint catalan(int n){
return combination(2*n,n)/(n+1);
}
};
int main(){
int N,M,K;
cin>>N>>M>>K;
K -= 2;
combi C(3000000);
mint ans = 0;
rep(_,2){
swap(N,M);
//K+2,K(same)
{
mint temp = 0;
temp = C.combination(N,K);
temp *= C.combination(M,K);
temp *= C.kaijou[K];
mint x = N-K;
x *= N-K-1;
x /= 2;
temp *= x;
temp *= K;
temp /= 3;
//cout<<temp.val()<<endl;
ans += temp;
}
//K+2,K(diff)
{
mint temp = 0;
temp = C.combination(N,K);
temp *= C.combination(M,K);
temp *= C.kaijou[K];
mint x = N-K;
x *= N-K-1;
x /= 2;
temp *= x;
temp *= K;
temp *= K-1;
temp /= 4;
//cout<<temp.val()<<endl;
ans += temp;
}
//K+1,K(both,not same)
{
mint temp = 0;
temp = C.combination(N,K);
temp *= C.combination(M,K);
temp *= C.kaijou[K];
mint x = N-K;
temp *= x;
temp *= K;
temp *= K-1;
temp /= 2;
temp /= 2;
//cout<<temp.val()<<endl;
//ans += temp;
}
//K+1,K(not both, same)
{
mint temp = 0;
temp = C.combination(N,K);
temp *= C.combination(M,K);
temp *= C.kaijou[K];
mint x = K;
x *= K;
x -= K;
x *= N-K;
x /= 2;
temp *= x;
//cout<<temp.val()<<endl;
ans += temp;
}
//K+1,K(not both, not same)
{
mint temp = 0;
temp = C.combination(N,K);
temp *= C.combination(M,K);
temp *= C.kaijou[K];
mint x = K;
x *= K;
x -= K;
x *= N-K;
x *= K-1;
temp *= x;
temp /= 2;
//cout<<temp.val()<<endl;
ans += temp;
}
}
//K,K
{
mint temp = 0;
temp = C.combination(N,K);
temp *= C.combination(M,K);
temp *= C.kaijou[K];
mint x = K;
x *= K;
x -= K;
x *= x-1;
x /= 2;
mint sub = K;
sub *= K-1;
sub /= 2;
sub /= 2;
x -= sub;
temp *= x;
//cout<<temp.val()<<endl;
ans += temp;
}
//K+1,K+1
{
mint temp = 0;
temp = C.combination(N,K);
temp *= C.combination(M,K);
temp *= C.kaijou[K];
mint x = M-K;
x *= N-K;
temp *= x;
temp *= K;
temp *= K-1;
temp /= 4;
//cout<<temp.val()<<endl;
ans += temp;
}
cout<<ans.val()<<endl;
return 0;
}
沙耶花