結果

問題 No.1872 Dictionary Order
ユーザー kabipoyokabipoyo
提出日時 2022-03-22 23:30:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,558 bytes
コンパイル時間 5,051 ms
コンパイル使用メモリ 260,992 KB
実行使用メモリ 34,944 KB
最終ジャッジ日時 2024-04-19 01:10:04
合計ジャッジ時間 6,512 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
34,944 KB
testcase_01 WA -
testcase_02 AC 20 ms
18,048 KB
testcase_03 AC 4 ms
6,016 KB
testcase_04 AC 30 ms
26,368 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 15 ms
13,568 KB
testcase_07 AC 7 ms
8,832 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 7 ms
7,296 KB
testcase_10 AC 12 ms
10,624 KB
testcase_11 AC 21 ms
17,152 KB
testcase_12 AC 5 ms
6,784 KB
testcase_13 AC 6 ms
6,656 KB
testcase_14 AC 20 ms
16,512 KB
testcase_15 AC 23 ms
19,584 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 11 ms
11,136 KB
testcase_18 AC 15 ms
13,184 KB
testcase_19 AC 11 ms
9,600 KB
testcase_20 AC 9 ms
7,424 KB
testcase_21 AC 19 ms
14,208 KB
testcase_22 AC 33 ms
27,904 KB
testcase_23 AC 14 ms
12,544 KB
testcase_24 AC 10 ms
9,600 KB
testcase_25 AC 20 ms
17,152 KB
testcase_26 AC 9 ms
9,344 KB
testcase_27 AC 17 ms
16,768 KB
testcase_28 AC 29 ms
24,576 KB
testcase_29 AC 32 ms
26,880 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 36 ms
30,336 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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, M;
	cin >> N >> M;
	vi v(N), w(N);
	vin(v);
	vin(w);

	lint a=0, b=0, c=0, x, y, z;
	vvi dp(N+1, vi(M+1));
	dp[0][0] = 1;
	reverse(all(v));
	rep(i, N) {
		rep(j, M) {
			chmax(dp[i+1][j], dp[i][j]);
			if (j+v[i] <= M) chmax(dp[i+1][j+v[i]], dp[i][j]);
		}
	}
	if (dp[N][M] != 1) drop(-1);
	reverse(all(v));
	reverse(all(dp));
	queue<lint> q;
	rep(t, N) {
		a = LINF;
		repx(i, t, N) {
			if (b+v[i] <= M && dp[i+1][M-b-v[i]]) {
				if (chmin(a, w[i])) t = i;
			}
		}
		q.push(t+1);
		b += v[t];
		if (b == M) break;
	}
	std::cout << q.size() << '\n';
	while (!q.empty()) {
		std::cout << q.front() << ' ';
		q.pop();
	}
	cout << endl;
}
0