結果

問題 No.1508 Avoid being hit
ユーザー KoDKoD
提出日時 2021-05-14 23:12:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 3,000 ms
コード長 3,881 bytes
コンパイル時間 2,407 ms
コンパイル使用メモリ 207,300 KB
実行使用メモリ 14,372 KB
最終ジャッジ日時 2024-04-10 05:34:34
合計ジャッジ時間 5,657 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
11,176 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 23 ms
8,192 KB
testcase_17 AC 14 ms
6,940 KB
testcase_18 AC 13 ms
6,940 KB
testcase_19 AC 19 ms
7,168 KB
testcase_20 AC 33 ms
9,600 KB
testcase_21 AC 21 ms
7,424 KB
testcase_22 AC 26 ms
8,448 KB
testcase_23 AC 29 ms
8,960 KB
testcase_24 AC 50 ms
13,940 KB
testcase_25 AC 45 ms
13,260 KB
testcase_26 AC 5 ms
6,940 KB
testcase_27 AC 24 ms
8,320 KB
testcase_28 AC 24 ms
8,448 KB
testcase_29 AC 47 ms
13,288 KB
testcase_30 AC 26 ms
8,576 KB
testcase_31 AC 41 ms
12,040 KB
testcase_32 AC 44 ms
12,824 KB
testcase_33 AC 13 ms
6,940 KB
testcase_34 AC 43 ms
12,580 KB
testcase_35 AC 6 ms
6,940 KB
testcase_36 AC 25 ms
8,576 KB
testcase_37 AC 12 ms
6,944 KB
testcase_38 AC 34 ms
10,368 KB
testcase_39 AC 23 ms
8,064 KB
testcase_40 AC 45 ms
12,824 KB
testcase_41 AC 27 ms
8,576 KB
testcase_42 AC 46 ms
12,896 KB
testcase_43 AC 53 ms
14,372 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

class rep {
    struct Iter {
        usize itr;
        constexpr Iter(const usize pos) noexcept : itr(pos) {}
        constexpr void operator++() noexcept { ++itr; }
        constexpr bool operator!=(const Iter& other) const noexcept { return itr != other.itr; }
        constexpr usize operator*() const noexcept { return itr; }
    };
    const Iter first, last;

  public:
    explicit constexpr rep(const usize first, const usize last) noexcept : first(first), last(std::max(first, last)) {}
    constexpr Iter begin() const noexcept { return first; }
    constexpr Iter end() const noexcept { return last; }
};

class revrep {
    struct Iter {
        usize itr;
        constexpr Iter(const usize pos) noexcept : itr(pos) {}
        constexpr void operator++() noexcept { --itr; }
        constexpr bool operator!=(const Iter& other) const noexcept { return itr != other.itr; }
        constexpr usize operator*() const noexcept { return itr; }
    };
    const Iter first, last;

  public:
    explicit constexpr revrep(const usize first, const usize last) noexcept
        : first(last - 1), last(std::min(first, last) - 1) {}
    constexpr Iter begin() const noexcept { return first; }
    constexpr Iter end() const noexcept { return last; }
};

template <class T> using Vec = std::vector<T>;

void concat(Vec<std::pair<usize, usize>>& vec) {
    Vec<std::pair<usize, usize>> ret;
    ret.push_back(vec.front());
    for (const auto i : rep(1, vec.size())) {
        const auto [l, r] = vec[i];
        if (l <= ret.back().second) {
            ret.back().second = r;
        } else {
            ret.emplace_back(l, r);
        }
    }
    vec = std::move(ret);
}

void del(Vec<std::pair<usize, usize>>& vec, const usize pos) {
    Vec<std::pair<usize, usize>> ret;
    for (const auto [l, r] : vec) {
        if (l <= pos and pos < r) {
            if (l != pos) {
                ret.emplace_back(l, pos);
            }
            if (pos + 1 != r) {
                ret.emplace_back(pos + 1, r);
            }
        } else {
            ret.emplace_back(l, r);
        }
    }
    vec = std::move(ret);
}

void D_main() {
    usize N, Q;
    std::cin >> N >> Q;
    Vec<usize> A(Q), B(Q);
    for (auto& x : A) {
        std::cin >> x;
        x -= 1;
    }
    for (auto& x : B) {
        std::cin >> x;
        x -= 1;
    }
    Vec<Vec<std::pair<usize, usize>>> vec(Q + 1);
    vec[0].emplace_back(0, N);
    for (const auto i : rep(0, Q)) {
        for (const auto [l, r] : vec[i]) {
            vec[i + 1].emplace_back((l == 0 ? 0 : l - 1), (r == N ? N : r + 1));
        }
        concat(vec[i + 1]);
        del(vec[i + 1], A[i]);
        del(vec[i + 1], B[i]);
        if (vec[i + 1].empty()) {
            std::cout << "NO\n";
            return;
        }
    }
    std::cout << "YES\n";
    Vec<usize> pos;
    pos.push_back(vec[Q].front().first);
    for (const auto i : revrep(0, Q)) {
        bool f = false;
        for (const auto [l, r] : vec[i]) {
            if (pos.back() + 1 == l) {
                pos.push_back(l);
                f = true;
            } else if (r == pos.back()) {
                pos.push_back(r - 1);
                f = true;
            } else if (l <= pos.back() and pos.back() < r) {
                pos.push_back(pos.back());
                f = true;
            }
            if (f) {
                break;
            }
        }
    }
    std::reverse(pos.begin(), pos.end());
    for (const auto x : pos) {
        std::cout << x + 1 << '\n';
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    D_main();
    return 0;
}
0