結果

問題 No.393 2本の竹
ユーザー ama_nukoama_nuko
提出日時 2018-06-24 23:53:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 1,000 ms
コード長 1,357 bytes
コンパイル時間 935 ms
コンパイル使用メモリ 100,272 KB
実行使用メモリ 45,868 KB
最終ジャッジ日時 2023-09-13 13:49:51
合計ジャッジ時間 3,762 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 224 ms
43,804 KB
testcase_10 AC 62 ms
15,884 KB
testcase_11 AC 78 ms
16,652 KB
testcase_12 AC 91 ms
18,436 KB
testcase_13 AC 59 ms
12,328 KB
testcase_14 AC 36 ms
10,704 KB
testcase_15 AC 24 ms
16,708 KB
testcase_16 AC 70 ms
27,232 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 109 ms
22,752 KB
testcase_23 AC 55 ms
15,872 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 194 ms
45,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int d;
    cin >> d;

    while(d > 0){
        int n1, n2, m;
        cin >> n1 >> n2 >> m;

        vector<int> a(m);
        rep(i, m) cin >> a[i];
        sort(a.begin(), a.end());

        vector<int> s(m);
        s[0] = a[0];
        for(int i = 1; i < m; i++){
            s[i] = s[i-1] + a[i];
        }

        vector<vector<int>> dp(m+1, vector<int>(n1+1, -1));
        dp[0][0] = 0;
        rep(i, m){
            rep(j, n1+1){
                if(dp[i][j] == -1){
                    continue;
                }

                if(j + a[i] <= n1){
                    dp[i+1][j+a[i]] = dp[i][j] + 1;
                }

                if(s[i] - j <= n2){
                    dp[i+1][j] = dp[i][j] + 1;
                }
            }
        }

        int ans = 0;
        rep(i, m+1){
            rep(j, n1+1){
                if(ans < dp[i][j]){
                    ans = dp[i][j];
                }
            }
        }
        cout << ans << endl;

        d--;
    }

    return 0;
}
0