結果

問題 No.2741 Balanced Choice
ユーザー PechiPechi
提出日時 2024-04-20 12:11:42
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 2,277 bytes
コンパイル時間 3,843 ms
コンパイル使用メモリ 163,100 KB
実行使用メモリ 104,016 KB
最終ジャッジ日時 2024-04-20 12:11:53
合計ジャッジ時間 6,983 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 222 ms
101,148 KB
testcase_01 AC 238 ms
104,016 KB
testcase_02 AC 238 ms
102,016 KB
testcase_03 AC 278 ms
103,680 KB
testcase_04 AC 256 ms
101,652 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 137 ms
68,136 KB
testcase_08 AC 189 ms
90,532 KB
testcase_09 AC 130 ms
64,128 KB
testcase_10 AC 151 ms
73,216 KB
testcase_11 AC 213 ms
91,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include<unordered_set>
#include<random>
#include <array>
#include <complex>
#include<chrono>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define LP(I,S,G) for (long long int I = (S); I < (G); ++I)
#define IN(X) 	for (int in = 0; in < X.size(); in++)cin >> X[in]
#define OUT(X) 	for (int in = 0; in < X.size(); in++)cout << X[in]<<" "
#define SORT(X) sort((X).begin(), (X).end())
#define CSORT(X,Y) sort(X.begin(), X.end(),Y)
#define COPY(X,Y) copy(X.begin(), X.end(), Y.begin())
#define ALL(X,Y) for (auto &(X) :(Y))
#define FULL(a)  (a).begin(),(a).end()
#define BFS(Q,S) for(Q.push(S);Q.size()!=0;Q.pop())
typedef long long int ll;
typedef unsigned long long int ull;
long long int M = 998244353;

chrono::system_clock::time_point starttime;
using namespace std::chrono;

inline float getTime() {
	return duration_cast<milliseconds>(system_clock::now() - starttime).count();
}


int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };

ll MAX(ll A, ll B) { return ((A) > (B) ? (A) : (B)); }
ll MIN(ll A, ll B) { return ((A) < (B) ? (A) : (B)); }
inline long long int xor128() {
	static long long int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	long long int t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

vector<ll> solve(vector<ll>& c, vector<ll>& v, ll w) {
	ll n = c.size();
	vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, -1));
	dp[0][0] = 0;
	LP(i, 0, n) {
		LP(k, 0, w + 1) {
			if (dp[i][k] == -1)continue;
			dp[i + 1][k] = max(dp[i + 1][k], dp[i][k]);
			if (k + c[i] <= w)dp[i + 1][k + c[i]] = max(dp[i + 1][k + c[i]], dp[i][k] + v[i]);
		}
	}
	return dp[n];
}

int main() {
	ll n, w, d;
	cin >> n >> w >> d;
	vector<vector<ll>> c(2), v(2);
	LP(i, 0, n) {
		ll t, x, y;
		cin >> t >> x >> y;
		c[t].push_back(x);
		v[t].push_back(y);
	}
	vector<ll> ans1 = solve(c[0], v[0], w), ans2 = solve(c[1], v[1], w);
	ll ans = 0;
	LP(i, 0, w + 1) {
		LP(k, i - d, i + d + 1) {
			if (k < 0 || k>w)continue;
			if (i + k > w)break;
			if (ans1[i] == -1 || ans2[k] == -1)continue;
			ans = max(ans, ans1[i] + ans2[k]);
		}
	}
	cout << ans;
	return 0;
}
0