結果

問題 No.393 2本の竹
ユーザー ふーらくたるふーらくたる
提出日時 2016-07-28 03:33:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 81 ms / 1,000 ms
コード長 1,565 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 64,952 KB
実行使用メモリ 30,796 KB
最終ジャッジ日時 2023-08-08 03:37:46
合計ジャッジ時間 2,606 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
30,736 KB
testcase_01 AC 25 ms
30,688 KB
testcase_02 AC 26 ms
30,640 KB
testcase_03 AC 32 ms
30,664 KB
testcase_04 AC 30 ms
30,660 KB
testcase_05 AC 29 ms
30,688 KB
testcase_06 AC 29 ms
30,668 KB
testcase_07 AC 33 ms
30,688 KB
testcase_08 AC 29 ms
30,632 KB
testcase_09 AC 81 ms
30,664 KB
testcase_10 AC 45 ms
30,632 KB
testcase_11 AC 54 ms
30,712 KB
testcase_12 AC 53 ms
30,636 KB
testcase_13 AC 44 ms
30,652 KB
testcase_14 AC 41 ms
30,636 KB
testcase_15 AC 17 ms
30,628 KB
testcase_16 AC 41 ms
30,692 KB
testcase_17 AC 34 ms
30,640 KB
testcase_18 AC 31 ms
30,636 KB
testcase_19 AC 24 ms
30,640 KB
testcase_20 AC 36 ms
30,640 KB
testcase_21 AC 35 ms
30,660 KB
testcase_22 AC 60 ms
30,652 KB
testcase_23 AC 47 ms
30,636 KB
testcase_24 AC 30 ms
30,744 KB
testcase_25 AC 26 ms
30,796 KB
testcase_26 AC 25 ms
30,756 KB
testcase_27 AC 70 ms
30,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

#define REP(i, x) for (int i = 0; i < (x); i++)
#define REPE(i, x) for (int i = 0; i <= (x); i++)
#define RREP(i, x) for (int i = (x) - 1; i >= 0; i--)
#define RREPE(i, x) for (int i = (x); i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORE(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define RFORE(i, a, b) for (int i = (a); i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()

typedef pair<int, int> PII;

const int kMaxN = 100010;
const int kMaxM = 70;

int dp[kMaxM][kMaxN];
int A[kMaxM];

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

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

        cin >> m;
        REP (i, m) {
            cin >> A[i];
        }

        sort(A, A + m);

        memset(dp, 0, sizeof(dp));

        int ans = 0, should_use = 0;
        FORE (b_num, 1, m) {
            REPE(use, n1) {

                if (use - A[b_num - 1] >= 0) {
                    dp[b_num][use] = max(dp[b_num][use], dp[b_num - 1][use - A[b_num - 1]] + 1);
                }

                int other_use = should_use - use;
                if (other_use >= 0 && other_use + A[b_num - 1] <= n2) {
                    dp[b_num][use] = max(dp[b_num][use], dp[b_num - 1][use] + 1);
                }
                ans = max(ans, dp[b_num][use]);
            }
            should_use += A[b_num - 1];
        }
        cout << ans << endl;
    }
    return 0;
}
0