結果
| 問題 |
No.393 2本の竹
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-14 17:09:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,453 bytes |
| コンパイル時間 | 1,094 ms |
| コンパイル使用メモリ | 88,456 KB |
| 実行使用メモリ | 20,132 KB |
| 最終ジャッジ日時 | 2024-10-15 01:09:56 |
| 合計ジャッジ時間 | 4,359 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 TLE * 1 -- * 18 |
ソースコード
#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;
}