結果
| 問題 |
No.393 2本の竹
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2016-07-14 21:52:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,631 bytes |
| コンパイル時間 | 851 ms |
| コンパイル使用メモリ | 98,348 KB |
| 実行使用メモリ | 39,548 KB |
| 最終ジャッジ日時 | 2024-10-15 01:10:40 |
| 合計ジャッジ時間 | 5,239 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 27 |
ソースコード
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
namespace std {
template <>
class hash<std::pair<int, int>> {
public:
size_t operator()(const std::pair<int, int>& x) const{
return hash<int>()(x.first) ^ hash<int>()(x.second);
}
};
}
int solve(int n1, int n2, const vector<int>& v){
unordered_map< pair<int,int>, int> dp[65];
dp[0][make_pair(0,0)] = 0;
rep(i,v.size()){
FOR(it,dp[i]){
pair<int,int> p = it->first;
int x = it->second;
dp[i+1][p] = max(dp[i+1][p], x);
if(p.first+v[i]<=n1) dp[i+1][make_pair(p.first+v[i],p.second)] = max(dp[i+1][make_pair(p.first+v[i],p.second)], x + 1);
if(p.second+v[i]<=n2) dp[i+1][make_pair(p.first,p.second+v[i])] = max(dp[i+1][make_pair(p.first,p.second+v[i])], x + 1);
}
}
int ret = 0;
FOR(it,dp[v.size()]){
ret = max(ret, it->second);
}
return ret;
}
int main(){
ios::sync_with_stdio(false);
int d;
cin >> d;
rep(i,d){
int n1, n2;
int m;
cin >> n1 >> n2;
cin >> m;
vector<int> A;
rep(j,m){
int a;
cin >> a;
A.push_back(a);
}
cout << solve(n1, n2, A) << endl;
}
return 0;
}
どらら