結果

問題 No.1457 ツブ消ししとるなHard
ユーザー boutarou
提出日時 2021-03-31 22:59:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,390 bytes
コンパイル時間 2,984 ms
コンパイル使用メモリ 195,844 KB
最終ジャッジ日時 2025-01-20 04:27:46
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 13 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int zero = 3000;
// dp[i][j][k] = 品物iまで見てj個購入して総和がk(-zero)の通り数
int 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);
    
    int n, m, x, y, z;
    cin >> n >> m >> x >> y >> z;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    x -= z, y -= z;
    rep(i, n) a[i] -= z;
    int sum = 0, cnt = 0;
    vector<int> 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];
                }
            }
        } 
    }
    int ans = 0;
    rep(i, m - cnt + 1) {
        ans += dp[think.size()][i][zero];
    }
    if(cnt == 0 && ans > 0) ans--;
    cout << ans << endl;
}
0