結果

問題 No.412 花火大会
ユーザー HachimoriHachimori
提出日時 2016-08-12 22:57:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 62,556 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-07 12:37:52
合計ジャッジ時間 1,305 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int NUM_FAMILY = 3;
const int NUM_SHEET = 30;


int needSize[NUM_FAMILY];
int numSheet, sheet[NUM_SHEET];

void read() {
    for (int i = 0; i < NUM_FAMILY; ++i) {
        cin >> needSize[i];
    }

    cin >> numSheet;
    for (int i = 0; i < numSheet; ++i) {
        cin >> sheet[i];
    }
}


int rec(int nThFamily, int nThSheet, int dp[NUM_FAMILY][NUM_SHEET]) {
    if (nThSheet == numSheet) {
        return nThFamily == 3 ? 1 : 0;
    }

    int &ret = dp[nThFamily][nThSheet];
    if (ret != -1) return ret;

    ret = 0;

    // Pick up sheet
    ret += rec(nThFamily + (nThFamily < NUM_FAMILY && needSize[nThFamily] <= sheet[nThSheet]),
               nThSheet + 1,
               dp);

    // Do not pick up sheet
    ret += rec(nThFamily, nThSheet + 1, dp);

    return ret;
}


void work() {
    sort(needSize, needSize + NUM_FAMILY);
    reverse(needSize, needSize + NUM_FAMILY);
    
    sort(sheet, sheet + numSheet);
    reverse(sheet, sheet + numSheet);

    int dp[NUM_FAMILY + 1][NUM_SHEET];
    memset(dp, -1, sizeof(dp));

    cout << rec(0, 0, dp) << endl;
}


int main() {
    read();
    work();
    return 0;
}
0