結果

問題 No.1872 Dictionary Order
ユーザー kabipoyokabipoyo
提出日時 2022-03-22 23:34:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 4,690 ms
コンパイル使用メモリ 260,612 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2024-04-19 01:14:05
合計ジャッジ時間 6,238 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
34,816 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 21 ms
18,176 KB
testcase_03 AC 4 ms
6,016 KB
testcase_04 AC 32 ms
26,368 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 15 ms
13,696 KB
testcase_07 AC 7 ms
8,832 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 7 ms
7,168 KB
testcase_10 AC 12 ms
10,624 KB
testcase_11 AC 20 ms
17,152 KB
testcase_12 AC 5 ms
6,400 KB
testcase_13 AC 6 ms
6,528 KB
testcase_14 AC 20 ms
16,512 KB
testcase_15 AC 24 ms
19,712 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 9 ms
11,136 KB
testcase_18 AC 14 ms
13,056 KB
testcase_19 AC 10 ms
9,728 KB
testcase_20 AC 8 ms
7,296 KB
testcase_21 AC 18 ms
14,080 KB
testcase_22 AC 33 ms
27,776 KB
testcase_23 AC 14 ms
12,416 KB
testcase_24 AC 9 ms
9,472 KB
testcase_25 AC 20 ms
17,152 KB
testcase_26 AC 9 ms
9,344 KB
testcase_27 AC 18 ms
16,640 KB
testcase_28 AC 29 ms
24,832 KB
testcase_29 AC 32 ms
26,880 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 36 ms
30,208 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+1) {
			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