結果

問題 No.1872 Dictionary Order
ユーザー ruthenruthen
提出日時 2022-03-11 22:51:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,540 bytes
コンパイル時間 1,759 ms
コンパイル使用メモリ 176,292 KB
実行使用メモリ 19,056 KB
最終ジャッジ日時 2023-10-19 12:37:40
合計ジャッジ時間 3,074 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
19,056 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 11 ms
10,608 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 17 ms
14,832 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 8 ms
8,496 KB
testcase_07 AC 5 ms
5,856 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 5 ms
5,328 KB
testcase_10 AC 7 ms
6,912 KB
testcase_11 AC 10 ms
10,344 KB
testcase_12 AC 4 ms
5,120 KB
testcase_13 AC 4 ms
4,800 KB
testcase_14 AC 10 ms
9,816 KB
testcase_15 AC 13 ms
11,400 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 7 ms
7,176 KB
testcase_18 AC 8 ms
8,232 KB
testcase_19 AC 6 ms
6,384 KB
testcase_20 AC 5 ms
5,328 KB
testcase_21 AC 9 ms
8,760 KB
testcase_22 AC 16 ms
15,624 KB
testcase_23 AC 7 ms
7,968 KB
testcase_24 AC 5 ms
6,384 KB
testcase_25 AC 10 ms
10,344 KB
testcase_26 AC 5 ms
6,384 KB
testcase_27 AC 10 ms
10,080 KB
testcase_28 AC 14 ms
14,040 KB
testcase_29 AC 16 ms
15,096 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 18 ms
16,680 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, M;
    cin >> N >> M;
    V<ll> A(N), P(N);
    rep(i, N) cin >> A[i];
    rep(i, N) {
        cin >> P[i];
        P[i]--;
    }
    V<V<int>> dp(N + 1, V<int>(M + 1, 0));
    dp[N][0] = 1;
    for (int i = N - 1; i >= 0; i--) {
        for (int j = 0; j <= M; j++) {
            if (dp[i + 1][j] == 0) continue;
            dp[i][j] = 1;
            if (j + A[i] <= M) dp[i][j + A[i]] = 1;
        }
    }
    if (dp[0][M] == 0) {
        cout << -1 << '\n';
        return 0;
    }
    V<int> ans;
    int lb = 0;
    while (M != 0) {
        int arg = -1;
        for (int i = lb; i < N; i++) {
            // A_iを使ってMを作れるか
            if (M - A[i] < 0) continue;
            if (dp[i + 1][M - A[i]] == 1) {
                if (arg == -1) {
                    arg = i;
                } else if (P[arg] > P[i]) {
                    arg = i;
                }
            }
        }
        assert(arg != -1);
        ans.push_back(arg);
        lb = arg + 1;
        M -= A[arg];
    }
    cout << ans.size() << '\n';
    rep(i, ans.size()) cout << ans[i] + 1 << (i == ans.size() - 1 ? '\n' : ' ');
    show(ans);
    return 0;
}
0