結果

問題 No.393 2本の竹
ユーザー masamasa
提出日時 2016-07-14 15:56:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,470 bytes
コンパイル時間 1,203 ms
コンパイル使用メモリ 93,748 KB
実行使用メモリ 19,868 KB
最終ジャッジ日時 2024-04-23 01:53:11
合計ジャッジ時間 5,693 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 382 ms
19,868 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 33 ms
5,376 KB
testcase_03 AC 168 ms
6,016 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 13 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 160 ms
6,040 KB
testcase_08 AC 782 ms
10,780 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>

using namespace std;

typedef pair<int, int> PII;

vector<vector<set<PII>>> dp;

void insert(int i, int j, PII p) {
	if (p.first < p.second) {
		swap(p.first, p.second);
	}
	if (p.second < 0) {
		return;
	}

	set<PII>& sp = dp[i][j];

	bool insertable = true;
	for (auto it = sp.begin(); it != sp.end();) {
		if (it->first >= p.first && it->second >= p.second) {
			insertable = false;
			break;
		}

		if (it->first <= p.first && it->second <= p.second) {
			it = sp.erase(it);
		} else {
			it++;
		}
	}

	if (insertable) {
		sp.insert(p);
	}
}

int solve() {
	int n1, n2, m;
	cin >> n1 >> n2 >> m;
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	if (n1 < n2) {
		swap(n1, n2);
	}

	dp.assign(m+1, vector<set<PII>>(m+1));
	dp[0][0].insert(make_pair(n1, n2));
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			dp[i+1][j] = dp[i][j];
		}
		for (int j = 0; j < m; j++) {
			for (auto p : dp[i][j]) {
				// insert(i+1, j, p);
				insert(i+1, j+1, make_pair(p.first - a[i], p.second));
				insert(i+1, j+1, make_pair(p.first, p.second - a[i]));
			}
		}
	}

	for (int i = m; i >= 0; i--) {
		if (dp[m][i].size() > 0) {
			return i;
		}
	}
	return 0;
}

int main() {
	int d;

	cin >> d;
	for (int i = 0; i < d; i++) {
		int ans = solve();
		cout << ans << endl;
	}
	return 0;
}
0