結果

問題 No.393 2本の竹
ユーザー roarisroaris
提出日時 2019-12-13 00:44:05
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 52 ms / 1,000 ms
コード長 1,306 bytes
コンパイル時間 2,013 ms
使用メモリ 8,744 KB
最終ジャッジ日時 2023-01-24 12:12:41
合計ジャッジ時間 3,086 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
4,904 KB
testcase_01 AC 1 ms
4,904 KB
testcase_02 AC 2 ms
6,952 KB
testcase_03 AC 1 ms
4,900 KB
testcase_04 AC 1 ms
4,904 KB
testcase_05 AC 2 ms
4,900 KB
testcase_06 AC 2 ms
6,948 KB
testcase_07 AC 1 ms
4,904 KB
testcase_08 AC 2 ms
4,904 KB
testcase_09 AC 52 ms
8,408 KB
testcase_10 AC 16 ms
5,012 KB
testcase_11 AC 19 ms
5,028 KB
testcase_12 AC 21 ms
5,336 KB
testcase_13 AC 15 ms
4,904 KB
testcase_14 AC 10 ms
4,904 KB
testcase_15 AC 8 ms
5,036 KB
testcase_16 AC 19 ms
6,948 KB
testcase_17 AC 2 ms
4,904 KB
testcase_18 AC 1 ms
4,904 KB
testcase_19 AC 1 ms
6,948 KB
testcase_20 AC 2 ms
4,900 KB
testcase_21 AC 2 ms
4,904 KB
testcase_22 AC 25 ms
5,660 KB
testcase_23 AC 14 ms
4,996 KB
testcase_24 AC 2 ms
4,900 KB
testcase_25 AC 2 ms
6,948 KB
testcase_26 AC 2 ms
4,904 KB
testcase_27 AC 46 ms
8,744 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