結果

問題 No.1872 Dictionary Order
ユーザー 👑 NachiaNachia
提出日時 2022-03-11 21:45:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,310 bytes
コンパイル時間 868 ms
コンパイル使用メモリ 84,408 KB
実行使用メモリ 19,416 KB
最終ジャッジ日時 2023-10-19 12:34:45
合計ジャッジ時間 2,237 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
19,416 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 10 ms
11,112 KB
testcase_03 AC 4 ms
4,812 KB
testcase_04 AC 14 ms
15,300 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 7 ms
8,796 KB
testcase_07 AC 5 ms
6,316 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 4 ms
5,684 KB
testcase_10 AC 6 ms
7,404 KB
testcase_11 AC 9 ms
10,648 KB
testcase_12 AC 4 ms
5,140 KB
testcase_13 AC 4 ms
5,316 KB
testcase_14 AC 9 ms
10,260 KB
testcase_15 AC 11 ms
11,880 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 6 ms
7,532 KB
testcase_18 AC 7 ms
8,580 KB
testcase_19 AC 5 ms
6,856 KB
testcase_20 AC 4 ms
5,712 KB
testcase_21 AC 8 ms
9,132 KB
testcase_22 AC 18 ms
16,016 KB
testcase_23 AC 8 ms
8,312 KB
testcase_24 AC 6 ms
6,796 KB
testcase_25 AC 11 ms
10,640 KB
testcase_26 AC 6 ms
6,736 KB
testcase_27 AC 10 ms
10,372 KB
testcase_28 AC 16 ms
14,392 KB
testcase_29 AC 17 ms
15,544 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 19 ms
17,220 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 <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i64 = long long;
using m32 = atcoder::static_modint<998244353>;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


const int INF = 1001001;


int main(){
    int N,M; cin >> N >> M;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    vector<int> P(N);
    rep(i,N){ cin >> P[i]; P[i]--; }

    vector<vector<int>> dp(N+1);
    dp[N] = vector<int>(M+1, INF);
    dp[N][M] = 0;

    for(int i=N-1; i>=0; i--){
        dp[i] = dp[i+1];
        int w = A[i];
        for(int p=0; p+w<=M; p++){
            if(dp[i+1][p+w] != INF){
                if(dp[i][p] == INF || P[i] < P[dp[i][p]]) dp[i][p] = i;
            }
        }
    }

    if(dp[0][0] == INF){ cout << "-1\n"; }
    else{
        vector<int> ans;
        int i=0, w=0;
        while(w != M){
            int nx = dp[i][w];
            i = nx + 1; w += A[nx];
            ans.push_back(nx);
        }
        cout << ans.size() << '\n';
        rep(j,ans.size()){
            if(j) cout << ' ';
            cout << (ans[j] + 1);
        }
        cout << '\n';
    }
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0