結果

問題 No.1457 ツブ消ししとるなHard
ユーザー tomoT222tomoT222
提出日時 2021-03-31 22:19:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 3,074 bytes
コンパイル時間 1,140 ms
コンパイル使用メモリ 103,880 KB
実行使用メモリ 57,204 KB
最終ジャッジ日時 2023-08-22 02:32:06
合計ジャッジ時間 2,594 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,372 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 54 ms
57,112 KB
testcase_05 AC 50 ms
52,944 KB
testcase_06 AC 54 ms
57,168 KB
testcase_07 AC 42 ms
57,204 KB
testcase_08 AC 12 ms
17,320 KB
testcase_09 AC 14 ms
17,308 KB
testcase_10 AC 14 ms
17,296 KB
testcase_11 AC 5 ms
5,808 KB
testcase_12 AC 50 ms
57,116 KB
testcase_13 AC 15 ms
17,352 KB
testcase_14 AC 15 ms
17,248 KB
testcase_15 AC 29 ms
34,716 KB
testcase_16 AC 45 ms
57,172 KB
testcase_17 AC 13 ms
17,384 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 55 ms
57,180 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<ctime>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<bitset>
#include<functional>
#include <fstream>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
#define puts(x) cout << (x) << "\n"
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;
//const ld EPS = 1e-9;

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
//main関数内に extGCD(a, b, x, y); でx, yに解が格納
ll extGCD(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}
//printf("%.10f\n", n);
typedef pair <ll, ll> P;
typedef pair <ld, ll> pp;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
struct edge { ll to, cost; };
struct status {
	ll ima;
	ll cost;

	bool operator<(const status& rhs) const { return cost < rhs.cost; };
	bool operator>(const status& rhs) const { return cost > rhs.cost; };
};



signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	//cout << fixed << setprecision(15);

	//input
	ll n, m, x, y, z; cin >> n >> m >> x >> y >> z;
	vector<ll>v;
	ll cnt = 0, sum = 0;
	rep(i, n) {
		ll a; cin >> a;
		if (y < a && a < x) { v.push_back(a); }
		if (a >= x) { cnt++; sum += a; }
	}
	vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(n + 1, vector<ll>(2600)));
	dp[0][0][0] = 1;
	rep(i, v.size()) {
		rep(j, n + 1) {
			rep(k, 2600) {
				if (v[i] <= k && j != 0) { dp[i + 1][j][k] += dp[i][j - 1][k - v[i]]; }
				dp[i + 1][j][k] += dp[i][j][k];
			}
		}
	}
	if (cnt > m) { cout << "Handicapped\n"; return 0; }
	ll ans = 0;
	rep(i, m - cnt + 1) {
		ll ok = z * (i + cnt) - sum; if (i + cnt == 0) { continue; }
		if (ok < 0) { continue; }
		ans += dp[v.size()][i][ok];// cout << i << ' ' << ok << ' ' << dp[v.size()][i][ok] << endl;
	}
	cout << ans << endl;
	return 0;
}
0