結果

問題 No.1872 Dictionary Order
ユーザー 👑 colognecologne
提出日時 2022-03-11 21:30:04
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 984 bytes
コンパイル時間 3,341 ms
コンパイル使用メモリ 247,928 KB
実行使用メモリ 4,536 KB
最終ジャッジ日時 2023-10-14 06:18:11
合計ジャッジ時間 6,953 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 2 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 2 ms
4,352 KB
testcase_31 WA -
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using Line = bitset<2001>;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for (int &a : A)
        cin >> a;
    vector<int> P(N);
    for (int &p : P)
        cin >> p;
    vector<int> Pinv(N);
    for (int i = 0; i < N; ++i)
        Pinv[P[i] - 1] = i;
    int last_idx = -1;
    vector<int> ans;
    for (int i = 0; i < N; ++i)
    {
        int p_idx = Pinv[i];
        if (p_idx < last_idx)
            continue;
        Line z = 0;
        z[0] = 1;
        for (int j = p_idx + 1; j < N; ++j)
            z |= z << A[j];
        if (M >= A[p_idx] && z[M - A[p_idx]])
        {
            ans.push_back(p_idx + 1);
            last_idx = p_idx;
            M -= A[p_idx];
            i = 0;
        }
    }
    if (ans.empty())
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans.size() << endl;
        for (int x : ans)
            cout << x << " ";
        cout << endl;
    }
}
0