結果

問題 No.1457 ツブ消ししとるなHard
ユーザー MisterMister
提出日時 2021-03-31 21:11:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 418 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 1,043 ms
コンパイル使用メモリ 93,516 KB
実行使用メモリ 23,808 KB
最終ジャッジ日時 2024-05-09 03:51:17
合計ジャッジ時間 2,458 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>

using namespace std;
using lint = long long;

void solve() {
    int n, m, l, r, z;
    cin >> n >> m >> r >> l >> z;

    vector<int> xs;
    int def = 0, cnt = 0;
    while (n--) {
        int x;
        cin >> x;

        if (x <= l) {
            continue;
        } else if (x >= r) {
            def += x - z;
            ++cnt;
        } else {
            xs.push_back(x - z);
        }
    }

    if (cnt > m) {
        cout << "Handicapped\n";
        return;
    }
    n = xs.size();

    map<tuple<int, int, int>, lint> dp;
    auto dfs = [&](auto&& f, int i, int sum, int num) -> lint {
        if (i == n) {
            return sum == 0 && 0 < num && num <= m ? 1 : 0;
        }

        auto t = make_tuple(i, sum, num);
        if (dp.count(t)) return dp[t];

        auto& ret = dp[t];
        ret = 0;

        for (int k = 0; k < 2; ++k) {
            auto nsum = sum + xs[i] * k;
            auto nnum = num + k;
            ret += f(f, i + 1, nsum, nnum);
        }
        return ret;
    };

    cout << dfs(dfs, 0, def, cnt) << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0