結果

問題 No.2701 A cans -> B cans
ユーザー shobonvipshobonvip
提出日時 2024-03-29 21:26:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,879 bytes
コンパイル時間 4,852 ms
コンパイル使用メモリ 267,944 KB
実行使用メモリ 209,044 KB
最終ジャッジ日時 2024-03-29 21:27:29
合計ジャッジ時間 50,021 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 18 ms
6,676 KB
testcase_04 AC 4 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 5 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 4 ms
6,676 KB
testcase_13 AC 4 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 4 ms
6,676 KB
testcase_16 AC 4 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 4 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 3 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 4 ms
6,676 KB
testcase_23 AC 170 ms
202,488 KB
testcase_24 AC 195 ms
202,488 KB
testcase_25 AC 194 ms
202,488 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 TLE -
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 TLE -
testcase_45 TLE -
testcase_46 TLE -
testcase_47 TLE -
testcase_48 TLE -
testcase_49 TLE -
testcase_50 TLE -
testcase_51 TLE -
testcase_52 TLE -
testcase_53 TLE -
testcase_54 TLE -
testcase_55 TLE -
testcase_56 AC 6 ms
6,676 KB
testcase_57 AC 4 ms
6,676 KB
testcase_58 AC 5 ms
6,676 KB
testcase_59 AC 5 ms
6,676 KB
testcase_60 AC 4 ms
6,676 KB
testcase_61 AC 3 ms
6,676 KB
testcase_62 AC 4 ms
6,676 KB
testcase_63 AC 4 ms
6,676 KB
testcase_64 AC 5 ms
6,676 KB
testcase_65 AC 5 ms
6,676 KB
testcase_66 TLE -
testcase_67 TLE -
testcase_68 TLE -
testcase_69 TLE -
testcase_70 TLE -
testcase_71 TLE -
testcase_72 TLE -
testcase_73 TLE -
testcase_74 TLE -
testcase_75 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	int n, m; cin >> n >> m;
	vector<ll> a(n), b(n), c(n);
	rep(i,0,n) cin >> a[i] >> b[i] >> c[i];

	vector<ll> dp(m+1);
	vector dp_mode(m+1, vector<ll>(n));
	vector<bool> seen(m+1);
	vector seen_mode(m+1, vector<bool>(n));
	seen[0] = 1;
	auto calc = [&](auto self, int i, int j) -> ll {
		if (j == -1){
			if (seen[i]) return dp[i];
			ll ret = 0;
			rep(j,0,n){
				if (i < a[j]) continue;
				chmax(ret, self(self, i - a[j], j) + c[j] * b[j]);
			}
			seen[i] = 1;
			dp[i] = ret;
			return ret;
		}else{
			if (seen_mode[i][j]) return dp_mode[i][j];
			ll ret = 0;
			if (i - a[j] + b[j] >= 0){
				chmax(ret, self(self, i - a[j] + b[j], j) + c[j] * b[j]);
			}
			chmax(ret, self(self, i, -1));
			seen_mode[i][j] = 1;
			dp_mode[i][j] = ret;
			return ret;
		}
	};

	rep(i,1,m+1){
		cout << calc(calc, i, -1) << '\n';
	}

}

0