結果

問題 No.1508 Avoid being hit
ユーザー KudeKude
提出日時 2021-05-14 23:31:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 3,000 ms
コード長 3,642 bytes
コンパイル時間 4,662 ms
コンパイル使用メモリ 259,072 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-04-10 05:35:22
合計ジャッジ時間 7,230 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
8,448 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 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,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 20 ms
7,680 KB
testcase_17 AC 12 ms
6,944 KB
testcase_18 AC 12 ms
6,940 KB
testcase_19 AC 16 ms
6,944 KB
testcase_20 AC 27 ms
10,496 KB
testcase_21 AC 18 ms
7,808 KB
testcase_22 AC 23 ms
8,832 KB
testcase_23 AC 24 ms
9,856 KB
testcase_24 AC 25 ms
6,940 KB
testcase_25 AC 22 ms
6,940 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 13 ms
6,940 KB
testcase_28 AC 12 ms
6,940 KB
testcase_29 AC 22 ms
6,940 KB
testcase_30 AC 13 ms
6,940 KB
testcase_31 AC 19 ms
6,944 KB
testcase_32 AC 21 ms
6,940 KB
testcase_33 AC 7 ms
6,940 KB
testcase_34 AC 33 ms
11,392 KB
testcase_35 AC 8 ms
8,448 KB
testcase_36 AC 22 ms
10,112 KB
testcase_37 AC 13 ms
9,008 KB
testcase_38 AC 27 ms
10,880 KB
testcase_39 AC 20 ms
9,952 KB
testcase_40 AC 34 ms
11,520 KB
testcase_41 AC 22 ms
10,316 KB
testcase_42 AC 35 ms
11,564 KB
testcase_43 AC 41 ms
12,032 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    VI a(q), b(q);
    rep(i, q) cin >> a[i], a[i]--;
    rep(i, q) cin >> b[i], b[i]--;
    VVI from(n);
    int l = 0, r = n - 1;
    vector<vector<P>> history(n);
    rep(i, q) {
        if (a[i] > b[i]) swap(a[i], b[i]);
        if (a[i] == b[i]) b[i] = n + 5;
        // cout << i << ' ' << a[i] << ' ' << b[i] << endl;
        if (l == r) {
            if (l == a[i] || l == b[i]) {
                cout << "NO" << '\n';
                return 0;
            }
            if (0 <= l - 1) {
                l--;
                history[l].emplace_back(i, l + 1);
            }
            if (r + 1 < n) {
                r++;
                history[r].emplace_back(i, r - 1);
            }
        } else if (l + 1 == r) {
            if (l == a[i] || l == b[i]) l++;
            if (r == a[i] || r == b[i]) r--;
            if (!(l <= r)) {
                cout << "NO" << '\n';
                return 0;
            }
            if (0 <= l - 1) {
                l--;
                history[l].emplace_back(i, l + 1);
            }
            if (r + 1 < n) {
                r++;
                history[r].emplace_back(i, r - 1);
            }
        } else if (a[i] + 1 == b[i]) {
            //cout << "!!" <<i << ' ' << a[i] << ' ' << l << endl;
            if (a[i] == l) {
                l += 2;
            } else if (b[i] == r) {
                r -= 2;
            } else if (b[i] == l) {
                l += 1;
            } else if (a[i] == r) {
                r -= 1;
            } else if (l < a[i] && b[i] < r) {
                history[a[i]].emplace_back(i, a[i] - 1);
                history[b[i]].emplace_back(i, b[i] + 1);
            }
            if (0 <= l - 1) {
                l--;
                history[l].emplace_back(i, l + 1);
            }
            if (r + 1 < n) {
                r++;
                history[r].emplace_back(i, r - 1);
            }
        } else {
            if (l == a[i] || l == b[i]) {
                l += 1;
            }
            if (r == a[i] || r == b[i]) {
                r -= 1;
            }
            for(int x: {a[i], b[i]}) {
                if (l < x && x < r) {
                    history[x].emplace_back(i, x - 1);
                }
            }
            if (0 <= l - 1) {
                l--;
                history[l].emplace_back(i, l + 1);
            }
            if (r + 1 < n) {
                r++;
                history[r].emplace_back(i, r - 1);
            }
        }
        // cout << l +1<< ' ' << r+1 << endl;
    }
    cout << "YES" << '\n';
    VI ans(q);
    int now = l;
    rrep(i, q) {
        while(!history[now].empty() && history[now].back().first > i) history[now].pop_back();
        if (!history[now].empty() && history[now].back().first == i) {
            int nxt = history[now].back().second;
            history[now].pop_back();
            now = nxt;
        }
        ans[i] = now;
    }
    cout << ans[0] + 1 << '\n';
    rep(i, q) cout << ans[i] + 1 << '\n';
}
0