結果

問題 No.2429 Happiest Tabehodai Ways
ユーザー Ping Chung ChangPing Chung Chang
提出日時 2023-08-28 19:51:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,265 ms / 2,000 ms
コード長 1,129 bytes
コンパイル時間 1,774 ms
コンパイル使用メモリ 167,168 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-03 03:07:06
合計ジャッジ時間 8,342 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 628 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 23 ms
4,376 KB
testcase_14 AC 17 ms
4,376 KB
testcase_15 AC 437 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 52 ms
4,384 KB
testcase_19 AC 72 ms
4,380 KB
testcase_20 AC 33 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 112 ms
4,380 KB
testcase_30 AC 32 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 235 ms
4,376 KB
testcase_34 AC 57 ms
4,388 KB
testcase_35 AC 5 ms
4,376 KB
testcase_36 AC 289 ms
4,380 KB
testcase_37 AC 7 ms
4,380 KB
testcase_38 AC 7 ms
4,380 KB
testcase_39 AC 5 ms
4,376 KB
testcase_40 AC 1,265 ms
4,376 KB
testcase_41 AC 7 ms
4,380 KB
testcase_42 AC 1,139 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second

const int mxn = 1010;
const ll mod = 998244353;
const ll inf = 1e18;
pll dp[2][mxn];

inline ll mad(ll a,ll b){
	a += b;
	return a>=mod?a-mod:a;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,k;
	cin>>n>>k;
	pll arr[n];
	for(auto &i:arr)cin>>i.fs;
	for(auto &i:arr)cin>>i.sc;
	bool roll = false;
	pll big = {0,1};
	for(auto &i:dp)for(auto &j:i)j = {-inf,0};
	dp[roll][0] = {0,1};
	for(int i = 0;i<k;i++){
		roll ^= 1;
		for(int j = 0;j<=k;j++)dp[roll][j] = {-inf,0};
		for(auto &p:arr){
			for(int j = p.fs;j<=k;j++){
				auto &tmp = dp[roll^1][j-p.fs];
				if(tmp.fs+p.sc>dp[roll][j].fs)dp[roll][j] = {tmp.fs+p.sc,tmp.sc};
				else if(tmp.fs+p.sc == dp[roll][j].fs)dp[roll][j].sc = mad(dp[roll][j].sc,tmp.sc);
			}
		}
		for(int j = 0;j<=k;j++){
			if(big.fs<dp[roll][j].fs)big = dp[roll][j];
			else if(big.fs == dp[roll][j].fs)big.sc = mad(big.sc,dp[roll][j].sc);
		}
	}
	cout<<big.fs<<'\n'<<big.sc;
}
0