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