結果

問題 No.1388 Less than K
ユーザー 👑 kmjpkmjp
提出日時 2021-02-11 12:06:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 474 ms / 3,000 ms
コード長 1,848 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 200,728 KB
実行使用メモリ 12,992 KB
最終ジャッジ日時 2023-09-25 01:05:33
合計ジャッジ時間 13,210 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
12,868 KB
testcase_01 AC 19 ms
12,832 KB
testcase_02 AC 19 ms
12,944 KB
testcase_03 AC 19 ms
12,872 KB
testcase_04 AC 19 ms
12,872 KB
testcase_05 AC 20 ms
12,804 KB
testcase_06 AC 20 ms
12,944 KB
testcase_07 AC 19 ms
12,752 KB
testcase_08 AC 22 ms
12,720 KB
testcase_09 AC 19 ms
12,752 KB
testcase_10 AC 19 ms
12,896 KB
testcase_11 AC 19 ms
12,716 KB
testcase_12 AC 22 ms
12,964 KB
testcase_13 AC 24 ms
12,892 KB
testcase_14 AC 26 ms
12,716 KB
testcase_15 AC 39 ms
12,696 KB
testcase_16 AC 48 ms
12,740 KB
testcase_17 AC 66 ms
12,988 KB
testcase_18 AC 99 ms
12,892 KB
testcase_19 AC 135 ms
12,720 KB
testcase_20 AC 144 ms
12,764 KB
testcase_21 AC 26 ms
12,700 KB
testcase_22 AC 23 ms
12,716 KB
testcase_23 AC 20 ms
12,764 KB
testcase_24 AC 21 ms
12,832 KB
testcase_25 AC 22 ms
12,872 KB
testcase_26 AC 21 ms
12,832 KB
testcase_27 AC 19 ms
12,720 KB
testcase_28 AC 19 ms
12,720 KB
testcase_29 AC 19 ms
12,816 KB
testcase_30 AC 19 ms
12,700 KB
testcase_31 AC 19 ms
12,756 KB
testcase_32 AC 19 ms
12,812 KB
testcase_33 AC 23 ms
12,804 KB
testcase_34 AC 23 ms
12,828 KB
testcase_35 AC 23 ms
12,736 KB
testcase_36 AC 23 ms
12,808 KB
testcase_37 AC 23 ms
12,944 KB
testcase_38 AC 29 ms
12,744 KB
testcase_39 AC 24 ms
12,832 KB
testcase_40 AC 27 ms
12,700 KB
testcase_41 AC 43 ms
12,724 KB
testcase_42 AC 22 ms
12,876 KB
testcase_43 AC 257 ms
12,800 KB
testcase_44 AC 214 ms
12,700 KB
testcase_45 AC 377 ms
12,744 KB
testcase_46 AC 317 ms
12,700 KB
testcase_47 AC 268 ms
12,700 KB
testcase_48 AC 231 ms
12,744 KB
testcase_49 AC 288 ms
12,700 KB
testcase_50 AC 270 ms
12,764 KB
testcase_51 AC 388 ms
12,744 KB
testcase_52 AC 460 ms
12,756 KB
testcase_53 AC 43 ms
12,752 KB
testcase_54 AC 35 ms
12,992 KB
testcase_55 AC 23 ms
12,944 KB
testcase_56 AC 68 ms
12,804 KB
testcase_57 AC 161 ms
12,772 KB
testcase_58 AC 274 ms
12,740 KB
testcase_59 AC 386 ms
12,748 KB
testcase_60 AC 474 ms
12,748 KB
testcase_61 AC 25 ms
12,756 KB
testcase_62 AC 23 ms
12,756 KB
testcase_63 AC 24 ms
12,700 KB
testcase_64 AC 26 ms
12,724 KB
testcase_65 AC 35 ms
12,808 KB
testcase_66 AC 44 ms
12,712 KB
testcase_67 AC 47 ms
12,752 KB
testcase_68 AC 117 ms
12,756 KB
testcase_69 AC 140 ms
12,768 KB
testcase_70 AC 206 ms
12,976 KB
testcase_71 AC 321 ms
12,760 KB
testcase_72 AC 28 ms
12,716 KB
testcase_73 AC 25 ms
12,756 KB
testcase_74 AC 24 ms
12,888 KB
testcase_75 AC 24 ms
12,828 KB
testcase_76 AC 23 ms
12,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

const ll mo=998244353;

ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

int H,W,K;
ll from[505],to[505];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>K;
	H--,W--;
	K/=2;
	ll ret=0;
	if(K<=500) {
		from[0]=1;
		for(x=0;x<=min(H,W);x++) {
			ll other=comb(H+W,H-x)*comb(W+x,W-x)%mo;
			(ret+=other*from[0])%=mo;
			FOR(i,K+1) to[i]=(from[abs(i-1)]+from[abs(i+1)])%mo;
			FOR(i,K+1) from[i]=(to[abs(i-1)]+to[abs(i+1)])%mo;
		}
	}
	else {
		for(x=0;x<=min(H,W);x++) {
			ll other=comb(H+W,H-x)*comb(W+x,W-x)%mo;
			ll R=comb(2*x,x);
			for(i=1;i*(K+1)<=x;i++) {
				if(i%2) R+=2*(mo-comb(2*x,x-i*(K+1)));
				else R+=2*comb(2*x,x-i*(K+1));
			}
			(ret+=R%mo*other)%=mo;
		}
	}
	
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0