結果

問題 No.1861 Required Number
ユーザー kabipoyokabipoyo
提出日時 2022-03-04 21:51:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 2,500 ms
コード長 1,615 bytes
コンパイル時間 4,300 ms
コンパイル使用メモリ 263,024 KB
実行使用メモリ 160,180 KB
最終ジャッジ日時 2023-09-26 03:27:25
合計ジャッジ時間 12,237 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 186 ms
160,088 KB
testcase_04 AC 181 ms
160,180 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 66 ms
55,544 KB
testcase_25 AC 163 ms
138,444 KB
testcase_26 AC 30 ms
25,356 KB
testcase_27 AC 63 ms
50,440 KB
testcase_28 AC 71 ms
58,516 KB
testcase_29 AC 43 ms
33,916 KB
testcase_30 AC 11 ms
9,284 KB
testcase_31 AC 164 ms
140,304 KB
testcase_32 AC 17 ms
13,744 KB
testcase_33 AC 115 ms
96,004 KB
testcase_34 AC 132 ms
113,960 KB
testcase_35 AC 137 ms
115,648 KB
testcase_36 AC 46 ms
36,100 KB
testcase_37 AC 70 ms
55,632 KB
testcase_38 AC 138 ms
117,868 KB
testcase_39 AC 83 ms
65,408 KB
testcase_40 AC 163 ms
139,856 KB
testcase_41 AC 154 ms
132,164 KB
testcase_42 AC 127 ms
107,420 KB
testcase_43 AC 71 ms
57,392 KB
testcase_44 AC 2 ms
4,380 KB
04_evil_1.txt MLE -
04_evil_2.txt MLE -
04_evil_3.txt MLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;

int main() {
	lint N, K;
	cin >> N >> K;
	vi v(N);
	vin(v);

	lint a=0, b=0, c=0, x, y, z;
	vvi dpl(N+1, vi(K+1)), dpr(N+1, vi(K+1));
	dpl[0][0] = 1;
	rep(i, N) {
		rep(j, K+1) {
			if (j+v[i] <= K) chmax(dpl[i+1][j+v[i]], dpl[i][j]);
			chmax(dpl[i+1][j], dpl[i][j]);
		}
	}
	dpr[N][0] = 1;
	rep(i, N) {
		rep(j, K+1) {
			if (j+v[N-i-1] <= K) chmax(dpr[N-1-i][j+v[N-i-1]], dpr[N-i][j]);
			chmax(dpr[N-1-i][j], dpr[N-i][j]);
		}
	}
	if (!dpl[N][K]) drop(-1);
	rep(i, N) {
		bool f = false;
		rep(j, K+1) {
			if (dpl[i][j] && dpr[i+1][K-j]) f = true;
		}
		if (f) continue;
		rep(j, K+1) {
			if (K-j-v[i] < 0) break;
			if (dpl[i][j] && dpr[i+1][K-j-v[i]]) f = true;
		}
		if (f) a++;
	}
	std::cout << a << '\n';
}
0