結果

問題 No.50 おもちゃ箱
ユーザー maimai
提出日時 2016-05-13 14:30:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 290 ms / 5,000 ms
コード長 965 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 177,280 KB
実行使用メモリ 19,808 KB
最終ジャッジ日時 2023-09-08 03:51:01
合計ジャッジ時間 3,481 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 14 ms
5,472 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 5 ms
4,376 KB
testcase_34 AC 290 ms
19,808 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 30 ms
7,052 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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,l=99;
    for (int i=m-1;i>=0;i--){
        if (bb[i]-weight[i]==l) continue;
        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;
        }
        l=bb[i]-weight[i];
    }
    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);
    
    sort(aa,aa+n);
    sort(bb,bb+m);
    
    vector<int> weight(m+1,0);
    i=calc(n-1,weight) ;
    cout <<(i>90?-1:i)<< endl;
    
	return 0;
}
0