結果

問題 No.2866 yuusaan's Knapsack
ユーザー 沙耶花沙耶花
提出日時 2024-08-30 21:44:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,112 bytes
コンパイル時間 4,430 ms
コンパイル使用メモリ 269,124 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-08-31 01:27:24
合計ジャッジ時間 5,344 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 9 ms
6,944 KB
testcase_07 AC 7 ms
6,944 KB
testcase_08 AC 9 ms
6,940 KB
testcase_09 AC 8 ms
6,940 KB
testcase_10 AC 8 ms
6,940 KB
testcase_11 AC 7 ms
6,944 KB
testcase_12 AC 8 ms
6,940 KB
testcase_13 AC 7 ms
6,940 KB
testcase_14 AC 8 ms
6,940 KB
testcase_15 AC 8 ms
6,944 KB
testcase_16 AC 8 ms
6,940 KB
testcase_17 AC 9 ms
6,944 KB
testcase_18 AC 6 ms
6,940 KB
testcase_19 AC 9 ms
6,944 KB
testcase_20 AC 8 ms
6,940 KB
testcase_21 AC 8 ms
6,940 KB
testcase_22 AC 8 ms
6,940 KB
testcase_23 AC 9 ms
6,944 KB
testcase_24 AC 8 ms
6,948 KB
testcase_25 AC 8 ms
6,944 KB
testcase_26 AC 6 ms
6,940 KB
testcase_27 AC 2 ms
6,944 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 Inf32 1000000001
#define Inf64 1000000000000000001
using P = pair<int,mint>;
P op(P a,P b){
	if(a.first>b.first)return a;
	if(a.first<b.first)return b;
	return P(a.first,a.second+b.second);
}
P e(){
	return make_pair(-Inf32,1);
}
int main(){
	
	int N,W;
	cin>>N>>W;
	
	vector<P> dp(20001,e());
	int c = 10000;
	dp[c] = make_pair(0,1);
	vector<pair<int,int>> items(N);
	rep(i,N){
		int x,y;
		cin>>x>>y;
		items[i] = make_pair(y,x);
	}
	sort(items.begin(),items.end());
	rep(i,N){
		int v,w;
		v = items[i].second,w = items[i].first;
		vector<P> ndp(20001,e());
		rep(j,20001){
			P val = dp[j];
			if(val.first==-Inf32)continue;
			ndp[j] = op(ndp[j],val);
			int nj = j + w;
			if(nj<0 || nj>=ndp.size())continue;
			val.first += v;
			ndp[nj] = op(ndp[nj],val);
		}
		swap(dp,ndp);
	}
	
	W += c;
	P ans = e();
	rep(i,W+1){
		ans = op(ans,dp[i]);
	}
	cout<<ans.first<<' '<<ans.second.val()<<endl;
    return 0;
}
0