結果

問題 No.1757 Many Many Cards
ユーザー 沙耶花沙耶花
提出日時 2021-11-20 13:49:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 4,638 ms
コンパイル使用メモリ 264,960 KB
実行使用メモリ 11,628 KB
最終ジャッジ日時 2023-09-02 07:42:04
合計ジャッジ時間 7,957 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
11,404 KB
testcase_01 AC 22 ms
11,484 KB
testcase_02 AC 22 ms
11,608 KB
testcase_03 AC 22 ms
11,404 KB
testcase_04 AC 21 ms
11,420 KB
testcase_05 AC 22 ms
11,624 KB
testcase_06 AC 22 ms
11,396 KB
testcase_07 AC 22 ms
11,360 KB
testcase_08 AC 22 ms
11,420 KB
testcase_09 AC 22 ms
11,396 KB
testcase_10 AC 21 ms
11,384 KB
testcase_11 AC 22 ms
11,424 KB
testcase_12 AC 22 ms
11,392 KB
testcase_13 AC 22 ms
11,440 KB
testcase_14 AC 22 ms
11,404 KB
testcase_15 AC 22 ms
11,404 KB
testcase_16 AC 22 ms
11,448 KB
testcase_17 AC 21 ms
11,484 KB
testcase_18 AC 22 ms
11,416 KB
testcase_19 AC 21 ms
11,388 KB
testcase_20 AC 21 ms
11,428 KB
testcase_21 AC 29 ms
11,444 KB
testcase_22 AC 55 ms
11,404 KB
testcase_23 AC 57 ms
11,408 KB
testcase_24 AC 43 ms
11,424 KB
testcase_25 AC 51 ms
11,400 KB
testcase_26 AC 22 ms
11,392 KB
testcase_27 AC 33 ms
11,540 KB
testcase_28 AC 60 ms
11,544 KB
testcase_29 AC 50 ms
11,392 KB
testcase_30 AC 24 ms
11,416 KB
testcase_31 AC 22 ms
11,480 KB
testcase_32 AC 38 ms
11,384 KB
testcase_33 AC 28 ms
11,412 KB
testcase_34 AC 28 ms
11,624 KB
testcase_35 AC 32 ms
11,392 KB
testcase_36 AC 73 ms
11,392 KB
testcase_37 AC 72 ms
11,628 KB
testcase_38 AC 22 ms
11,404 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 1000000001

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(){
	
	combi C(1000000);
	mint ans = 0;
	
	int N,M;
	cin>>N>>M;
	
	ans = mint(M).pow(N*2);
	ans *= M;
	
	for(int t=1;t<=200005;t++){
		if(t-1>N)break;
		mint temp = C.combination(N,t-1);		
		temp *= mint(2).pow(t-1);
		if(t>M)break;
		temp *= C.combination(M,t);
		temp *= C.kaijou[t-1];
		temp *= mint(M-t).pow((N-(t-1))*2);
		if(t>=3){
			temp *= mint(t).pow(t-2);
		}
		ans -= temp;		
	}
	
	cout<<ans.val()<<endl;
	
	return 0;
}
0