結果

問題 No.1872 Dictionary Order
ユーザー shiomusubi496shiomusubi496
提出日時 2021-12-19 15:30:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 744 bytes
コンパイル時間 2,052 ms
コンパイル使用メモリ 204,256 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-13 20:48:23
合計ジャッジ時間 7,460 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N), P(N);
    for (int i=0; i<N; ++i) cin >> A[i];
    for (int i=0; i<N; ++i) cin >> P[i];
    vector<int> B, H{N + 1};
    for (int i=0; i<(1<<N); ++i) {
        int sum = 0;
        vector<int> C, D;
        for (int j=0; j<N; ++j) {
            if ((i>>j) & 1) {
                sum += A[j];
                C.push_back(j);
                D.push_back(P[j]);
            }
        }
        if (sum == M && D < H) {
            B = C;
            H = D;
        }
    }
    if (B.empty()) puts("-1");
    else {
        cout << B.size() << endl;
        for (int i=0; i<B.size(); i++) cout << B[i] + 1 << " \n"[i == B.size()];
    }
}
0