結果

問題 No.1457 ツブ消ししとるなHard
ユーザー boutarouboutarou
提出日時 2021-03-31 23:06:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,440 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 203,140 KB
実行使用メモリ 140,616 KB
最終ジャッジ日時 2023-08-22 04:03:51
合計ジャッジ時間 3,439 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
15,828 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
7,560 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 67 ms
140,604 KB
testcase_05 AC 61 ms
134,504 KB
testcase_06 AC 66 ms
140,580 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 10 ms
36,312 KB
testcase_10 AC 10 ms
36,324 KB
testcase_11 AC 6 ms
23,880 KB
testcase_12 AC 31 ms
95,688 KB
testcase_13 AC 18 ms
54,548 KB
testcase_14 AC 11 ms
46,484 KB
testcase_15 AC 18 ms
56,616 KB
testcase_16 AC 11 ms
25,928 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
5,508 KB
testcase_19 AC 60 ms
140,616 KB
testcase_20 AC 2 ms
5,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
using ll = long long;
using P = pair<ll, ll>;

ll zero = 3000;
// dp[i][j][k] = 品物iまで見てj個購入して総和がk(-zero)の通り数
ll dp[55][55][6300];

// 6 3 6 2 4
// 2 2 3 5 1 1

// 2 -2
// newa = {x-2, x-2, -1, 1, x-3, x-3}


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n, m, x, y, z;
    cin >> n >> m >> x >> y >> z;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    x -= z, y -= z;
    rep(i, n) a[i] -= z;
    ll sum = 0, cnt = 0;
    vector<ll> think;
    rep(i, n) {
        if (a[i] >= x) {
            sum += a[i];
            cnt++;
        }
        else if (a[i] > y) {
            think.push_back(a[i]);
        }
    }
    if(cnt > m) {
        cout << "Handicapped" << endl;
        return 0;
    }
    dp[0][0][sum + zero] = 1;
    rep(i, think.size()) {
        rep(j, m - cnt + 1) {
            rep(k, zero * 2) {
                dp[i + 1][j][k] += dp[i][j][k];
                if(j != m - cnt && 0 <= k + think[i] && k + think[i] < zero * 2) {
                    dp[i + 1][j + 1][k + think[i]] += dp[i][j][k];
                }
            }
        } 
    }
    ll ans = 0;
    rep(i, m - cnt + 1) {
        if (i == 0) {
            if(cnt != 0) ans += dp[think.size()][i][zero];
        }
        else ans += dp[think.size()][i][zero];
    }
    cout << ans << endl;
}
0