結果

問題 No.393 2本の竹
ユーザー masamasa
提出日時 2016-07-14 17:09:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,453 bytes
コンパイル時間 1,424 ms
コンパイル使用メモリ 87,776 KB
実行使用メモリ 17,004 KB
最終ジャッジ日時 2024-04-23 01:53:36
合計ジャッジ時間 4,471 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
17,004 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 11 ms
6,940 KB
testcase_03 AC 44 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 6 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 42 ms
6,944 KB
testcase_08 AC 228 ms
8,576 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 <list>

using namespace std;

typedef pair<int, int> PII;

vector<vector<list<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;
	}

	list<PII>& lst = dp[i][j];

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

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

	if (pushable) {
		lst.push_back(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<list<PII>>(m+1));
	dp[0][0].push_back(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+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