結果

問題 No.2428 Returning Shuffle
ユーザー Ping Chung ChangPing Chung Chang
提出日時 2023-08-28 20:08:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,129 bytes
コンパイル時間 1,553 ms
コンパイル使用メモリ 167,156 KB
実行使用メモリ 19,320 KB
最終ジャッジ日時 2023-08-28 20:08:43
合計ジャッジ時間 7,904 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 RE -
testcase_20 RE -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

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