結果

問題 No.1508 Avoid being hit
ユーザー tamatotamato
提出日時 2021-05-14 23:40:48
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,199 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 146,048 KB
最終ジャッジ日時 2024-04-10 04:23:14
合計ジャッジ時間 6,210 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 41 ms
55,580 KB
testcase_02 AC 40 ms
54,336 KB
testcase_03 AC 40 ms
54,780 KB
testcase_04 AC 40 ms
54,696 KB
testcase_05 AC 41 ms
54,372 KB
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 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    import random
    input = sys.stdin.readline

    N, Q = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    ok = [1] * (N+2)
    ok[0] = ok[-1] = 0
    st = set()
    snapshot = [None] * Q
    for i in range(Q-1, -1, -1):
        a, b = A[i], B[i]
        st_new = set()
        for v in st:
            flg = ok[v-1] | ok[v] | ok[v+1]
            if flg:
                ok[v] = 1
                if ok[v-1] == 0 and v-1 != 0:
                    st_new.add(v-1)
                if ok[v+1] == 0 and v+1 != N+1:
                    st_new.add(v+1)
        st = st_new
        st.add(a)
        st.add(b)
        ok[a] = ok[b] = 0
        if i % 500 == 0 and i != 0:
            snapshot[i] = ok[:]
    if sum(ok) == 0:
        print("NO")
    else:
        print("YES")
        ans = []
        v0 = []
        for v in range(1, N+1):
            if ok[v]:
                v0.append(v)
        v = v0[len(v0) // 2]
        ans.append(v)
        t = 0
        while True:
            t0 = t
            if t0 == 0:
                v = random.sample(v0, 1)[0]
            if len(ans) == Q+1:
                break
            ok_flg = 1
            for _ in range(500):
                if len(ans) == Q + 1:
                    break
                a, b = A[t], B[t]
                R = random.sample(range(3), k=3)
                flg = 0
                for r in R:
                    u = v + r - 1
                    if u != a and u != b and u != 0 and u != N+1:
                        flg = 1
                        ans.append(u)
                        v = u
                        break
                if not flg:
                    ok_flg = 0
                    break
                t += 1
            if len(ans) == Q+1:
                break
            if not ok_flg:
                while len(ans) > t0 + 1:
                    ans.pop()
            else:
                if snapshot[t0 // 500 + 1][v] == 0:
                    while len(ans) > t0 + 1:
                        ans.pop()
        print(*ans, sep="\n")


if __name__ == '__main__':
    main()
0