結果

問題 No.2866 yuusaan's Knapsack
ユーザー 👑 kmjpkmjp
提出日時 2024-08-30 22:55:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,527 bytes
コンパイル時間 2,208 ms
コンパイル使用メモリ 203,672 KB
実行使用メモリ 66,256 KB
最終ジャッジ日時 2024-08-31 01:29:06
合計ジャッジ時間 3,597 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,092 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 4 ms
9,828 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 34 ms
65,008 KB
testcase_07 AC 29 ms
52,860 KB
testcase_08 AC 34 ms
60,992 KB
testcase_09 AC 30 ms
56,836 KB
testcase_10 AC 31 ms
60,772 KB
testcase_11 AC 24 ms
44,832 KB
testcase_12 AC 29 ms
55,044 KB
testcase_13 AC 26 ms
48,396 KB
testcase_14 AC 28 ms
55,364 KB
testcase_15 AC 33 ms
62,988 KB
testcase_16 AC 26 ms
48,856 KB
testcase_17 AC 35 ms
60,280 KB
testcase_18 AC 24 ms
42,684 KB
testcase_19 AC 36 ms
66,180 KB
testcase_20 AC 28 ms
53,392 KB
testcase_21 AC 30 ms
55,168 KB
testcase_22 AC 27 ms
53,016 KB
testcase_23 AC 35 ms
65,280 KB
testcase_24 AC 26 ms
50,856 KB
testcase_25 AC 32 ms
58,644 KB
testcase_26 AC 31 ms
66,256 KB
testcase_27 AC 3 ms
7,796 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;}
//-------------------------------------------------------

int N,W;

ll SW[101][40202];
ll SP[101][40202];
const ll mo=998244353;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>W;
	FOR(i,N) FOR(x,40201) SW[i][x]=-1LL<<30;
	SW[0][10000]=0;
	SP[0][10000]=1;
	FOR(i,N) {
		int v,w;
		cin>>v>>w;
		FOR(x,40000) {
			if(x+w>=0&&x+w<=40000) {
				if(SW[i+1][x+w]<SW[i][x]+v) SW[i+1][x+w]=SW[i][x]+v, SP[i+1][x+w]=0;
				if(SW[i+1][x+w]==SW[i][x]+v) (SP[i+1][x+w]+=SP[i][x])%=mo;
			}
			if(SW[i+1][x]<SW[i][x]) SW[i+1][x]=SW[i][x], SP[i+1][x]=0;
			if(SW[i+1][x]==SW[i][x]) (SP[i+1][x]+=SP[i][x])%=mo;
		}
	}
	int best=-1<<30;
	ll pat=0;
	for(i=0;i<=W+10000;i++) {
		if(SW[N][i]>best) best=SW[N][i],pat=0;
		if(SW[N][i]==best) pat+=SP[N][i];
	}
	cout<<best<<" "<<pat%mo<<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