結果

問題 No.1872 Dictionary Order
ユーザー se1ka2se1ka2
提出日時 2022-03-11 22:22:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 663 ms
コンパイル使用メモリ 74,256 KB
実行使用メモリ 31,456 KB
最終ジャッジ日時 2023-10-14 07:35:40
合計ジャッジ時間 8,057 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,985 ms
31,456 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,352 KB
testcase_06 WA -
testcase_07 AC 6 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 11 ms
4,352 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 9 ms
4,348 KB
testcase_15 AC 12 ms
4,348 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 WA -
testcase_18 AC 10 ms
4,348 KB
testcase_19 AC 7 ms
4,352 KB
testcase_20 WA -
testcase_21 AC 8 ms
4,348 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 3 ms
4,348 KB
testcase_31 WA -
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int a[2003], p[2003];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }
    vector<int> dp[2003];
    vector<int> ans[2003];
    for(int i = 1; i <= m; i++) dp[i] = {n};
    for(int i = 0; i < n; i++){
        for(int j = m; j >= a[i]; j--){
            if(dp[j] > dp[j - a[i]]){
                dp[j] = dp[j - a[i]];
                dp[j].push_back(p[i]);
                ans[j] = ans[j - a[i]];
                ans[j].push_back(i);
            }
        }
    }
    if(ans[m].size()){
        cout << ans[m].size() << endl;
        for(int i : ans[m]) cout << i + 1 << " ";
        cout << endl;
    }
    else{
        cout << -1 << endl;
    }
}
0