結果

問題 No.1508 Avoid being hit
ユーザー vwxyzvwxyz
提出日時 2023-07-18 11:44:04
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,218 bytes
コンパイル時間 3,820 ms
コンパイル使用メモリ 112,968 KB
実行使用メモリ 814,472 KB
最終ジャッジ日時 2023-10-18 14:50:57
合計ジャッジ時間 4,690 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
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 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

int main() {
    int N, Q;
    cin >> N >> Q;

    vector<int> A(Q);
    vector<int> B(Q);
    for (int q = 0; q < Q; ++q) {
        cin >> A[q];
        A[q] -= 1;
    }
    for (int q = 0; q < Q; ++q) {
        cin >> B[q];
        B[q] -= 1;
    }

    vector<bitset<100000>> dp(Q + 1);
    dp[0] = (1 << N) - 1;
    for (int q = 1; q <= Q; ++q) {
        dp[q] = dp[q - 1] >> 1 | dp[q - 1] | dp[q - 1] << 1;
        dp[q] &= ~(1 << N | 1 << A[q - 1] | 1 << B[q - 1]);
    }

    if (dp[Q].any()) {
        cout << "YES" << endl;
        int x;
        for (x = 0; x < N; ++x) {
            if (dp[Q][x]) {
                break;
            }
        }
        vector<int> ans_lst;
        ans_lst.push_back(x);
        for (int q = Q - 1; q >= 0; --q) {
            if (x - 1 >= 0 && dp[q][x - 1]) {
                x -= 1;
            } else if (x + 1 < N && dp[q][x + 1]) {
                x += 1;
            }
            ans_lst.push_back(x);
        }
        for (int i = ans_lst.size() - 1; i >= 0; --i) {
            cout << ans_lst[i] + 1 << endl;
        }
    } else {
        cout << "NO" << endl;
    }

    return 0;
}
0