結果

問題 No.393 2本の竹
ユーザー 114514114514
提出日時 2016-07-12 00:56:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 873 bytes
コンパイル時間 2,000 ms
コンパイル使用メモリ 170,696 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 01:46:26
合計ジャッジ時間 3,282 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,816 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 48 ms
6,940 KB
testcase_10 AC 12 ms
6,940 KB
testcase_11 AC 23 ms
6,940 KB
testcase_12 AC 24 ms
6,940 KB
testcase_13 AC 17 ms
6,940 KB
testcase_14 AC 7 ms
6,940 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 WA -
testcase_17 AC 4 ms
6,940 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 4 ms
6,948 KB
testcase_21 WA -
testcase_22 AC 28 ms
6,940 KB
testcase_23 WA -
testcase_24 AC 4 ms
6,944 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 36 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int T;
    cin>>T;
    while(T--){
        int a,b;
        cin>>a>>b;
        if(a>b){int tmp=b;b=a;a=tmp;}
        int n;
        cin>>n;
        vector<int> A(n);
        for(int i=0;i<n;i++)cin>>A[i];
        sort(A.begin(),A.end());
        vector<pair<int,int>> dp(100050);
        for(int i=0;i<100050;i++)dp[i]=make_pair(-1000000,-1000000);
        dp[0]=make_pair(0,b);
        for(int i=0;i<n;i++){
            for(int j=a-A[i];j>=0;j--){

                dp[j+A[i]]=max(dp[j+A[i]],make_pair(dp[j].first+1,dp[j].second));
                if(dp[j].second>=A[i]){
                    dp[j].first++;
                    dp[j].second-=A[i];
                }

            }
        }
        int ans=0;
        for(int i=0;i<=a;i++)
            ans=max(ans,dp[i].first);
        cout<<ans<<endl;
    }
}
0