結果

問題 No.50 おもちゃ箱
ユーザー koyoprokoyopro
提出日時 2015-09-30 01:06:54
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 941 bytes
コンパイル時間 4,388 ms
コンパイル使用メモリ 149,852 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 00:26:57
合計ジャッジ時間 3,724 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 4 ms
4,384 KB
testcase_02 WA -
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 6 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 6 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 8 ms
4,380 KB
testcase_33 AC 20 ms
4,380 KB
testcase_34 AC 1 ms
4,384 KB
testcase_35 AC 13 ms
4,380 KB
testcase_36 AC 8 ms
4,380 KB
testcase_37 AC 5 ms
4,380 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 4 ms
4,380 KB
testcase_40 AC 37 ms
4,384 KB
testcase_41 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define REP(i, n) for(int i=0; i<(n); i++)

#define ALL(a) (a).begin(),(a).end()
int N,M;
vector<int> A, B;
signed main()
{
    cin>>N;
    A.resize(N);
    REP(i,N) cin >> A[i];
    cin>>M;
    B.resize(M);
    REP(i,M) cin >> B[i];
    sort(ALL(B), greater<int>());
    int minbox = 100;
    do {
        int bi = 0;
        int space = B[bi++]; // 大きい物順に入れる
        bool error = false;
        REP(i,A.size()) {
            if (space >= A[i]) {
                space -= A[i];
            } else {
                space = B[bi++];
                if (space < A[i]) {
                    // 失敗
                    error = true;
                    break;
                }
                i--;
            }
        }
        if (!error) minbox = min(minbox, bi);
    }while(next_permutation(ALL(A)));

    cout << ((minbox < 100) ? minbox : -1) << endl;
    return 0;
}
0