結果

問題 No.393 2本の竹
ユーザー roarisroaris
提出日時 2019-12-13 00:44:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 1,000 ms
コード長 1,306 bytes
コンパイル時間 1,583 ms
コンパイル使用メモリ 167,940 KB
実行使用メモリ 8,588 KB
最終ジャッジ日時 2023-09-08 08:24:11
合計ジャッジ時間 3,112 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 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,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 54 ms
8,344 KB
testcase_10 AC 17 ms
4,864 KB
testcase_11 AC 20 ms
5,112 KB
testcase_12 AC 21 ms
5,232 KB
testcase_13 AC 16 ms
4,568 KB
testcase_14 AC 11 ms
4,376 KB
testcase_15 AC 9 ms
5,012 KB
testcase_16 AC 22 ms
6,336 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 26 ms
5,716 KB
testcase_23 AC 16 ms
4,936 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 45 ms
8,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int d; cin >> d;
    
    while(d) {
        int n1, n2; cin >> n1 >> n2;
        int m; cin >> m;
        int A[m];
        
        for (int i=0; i<m; i++) cin >> A[i];
        
        sort(A, A+m);
        bool dp[m+1][n1+1];
        
        for (int i=0; i<=m; i++) {
            for (int j=0; j<=n1; j++) {
                dp[i][j] = false;
            }
        }
        
        dp[0][0] = true;
        int acc = 0;
        
        for (int i=0; i<m; i++) {
            for (int j=0; j<=n1; j++) {
                if (j+A[i]<=n1) {
                    dp[i+1][j+A[i]] |= dp[i][j];
                }
                
                int n2_used = acc-j;
                
                if (n2_used+A[i]<=n2) {
                    dp[i+1][j] |= dp[i][j];
                }
            }
            
            acc += A[i];
        }
        
        bool flag = false;
        
        for (int i=m; i>=0; i--) {
            for (int j=0; j<=n1; j++) {
                if (dp[i][j]) {
                    cout << i << endl;
                    flag = true;
                    break;
                }
            }
            
            if (flag) {
                break;
            }
        }
        
        d--;
    }
}
0