結果

問題 No.50 おもちゃ箱
ユーザー maimai
提出日時 2016-05-13 14:13:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 845 bytes
コンパイル時間 1,879 ms
コンパイル使用メモリ 173,872 KB
実行使用メモリ 712,992 KB
最終ジャッジ日時 2024-04-15 15:29:35
合計ジャッジ時間 12,229 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,816 KB
testcase_01 AC 461 ms
52,608 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 264 ms
16,768 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 14 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 4 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 39 ms
10,624 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 133 ms
18,560 KB
testcase_33 AC 830 ms
94,464 KB
testcase_34 AC 532 ms
41,472 KB
testcase_35 AC 42 ms
9,856 KB
testcase_36 AC 58 ms
10,880 KB
testcase_37 AC 8 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 666 ms
59,904 KB
testcase_40 MLE -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

int aa[100],bb[100];
int n,m;

map<vector<int>,int> dp;

int calc(int idx,vector<int> &weight){
    if (idx<0) {
        return 0;
    }
    if (idx<n-1){
        weight[m]=idx;
        if (dp.count(weight)) return dp[weight];
    }
    
    int min=99,r;
    for (int i=0;i<m;i++){
        if (weight[i]+aa[idx]<=bb[i]){
            vector<int> v=weight;
            v[i]+=aa[idx];
            r = (weight[i]==0) + calc(idx-1,v);
            if (r<min) min=r;
        }
    }
    weight[m]=idx;
    dp[weight]=min;
    return min;
}

int main(){
	int i, j, k, l;

    cin >> n;
    for (i=0;i<n;i++)
        scanf("%d",aa+i);
    cin >> m;
    for (i=0;i<m;i++)
        scanf("%d",bb+i);
    
    vector<int> weight(m+1,0);
    i=calc(n-1,weight) ;
    cout <<(i>90?-1:i)<< endl;
    
	return 0;
}
0