結果

問題 No.1691 Badugi
ユーザー 沙耶花沙耶花
提出日時 2021-09-24 23:08:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 2,946 bytes
コンパイル時間 4,625 ms
コンパイル使用メモリ 267,596 KB
実行使用メモリ 27,876 KB
最終ジャッジ日時 2023-09-18 22:14:50
合計ジャッジ時間 6,664 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
27,796 KB
testcase_01 AC 60 ms
27,580 KB
testcase_02 AC 60 ms
27,580 KB
testcase_03 AC 60 ms
27,592 KB
testcase_04 AC 60 ms
27,616 KB
testcase_05 AC 60 ms
27,580 KB
testcase_06 AC 60 ms
27,744 KB
testcase_07 AC 60 ms
27,708 KB
testcase_08 AC 60 ms
27,588 KB
testcase_09 AC 60 ms
27,596 KB
testcase_10 AC 60 ms
27,580 KB
testcase_11 AC 60 ms
27,628 KB
testcase_12 AC 60 ms
27,600 KB
testcase_13 AC 60 ms
27,596 KB
testcase_14 AC 60 ms
27,876 KB
testcase_15 AC 60 ms
27,592 KB
testcase_16 AC 60 ms
27,592 KB
testcase_17 AC 59 ms
27,580 KB
testcase_18 AC 60 ms
27,700 KB
testcase_19 AC 60 ms
27,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0