結果

問題 No.1508 Avoid being hit
ユーザー tamatotamato
提出日時 2021-05-14 23:23:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,802 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 83,084 KB
実行使用メモリ 103,080 KB
最終ジャッジ日時 2024-04-10 03:44:34
合計ジャッジ時間 9,423 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 39 ms
53,788 KB
testcase_02 AC 37 ms
53,064 KB
testcase_03 AC 38 ms
53,524 KB
testcase_04 AC 38 ms
53,824 KB
testcase_05 AC 38 ms
53,372 KB
testcase_06 RE -
testcase_07 AC 38 ms
53,384 KB
testcase_08 AC 37 ms
53,124 KB
testcase_09 AC 38 ms
53,488 KB
testcase_10 AC 38 ms
53,476 KB
testcase_11 AC 39 ms
52,852 KB
testcase_12 AC 38 ms
53,408 KB
testcase_13 AC 37 ms
54,012 KB
testcase_14 AC 37 ms
53,580 KB
testcase_15 WA -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 103 ms
93,716 KB
testcase_35 AC 63 ms
73,968 KB
testcase_36 AC 85 ms
84,572 KB
testcase_37 AC 72 ms
78,256 KB
testcase_38 AC 94 ms
89,060 KB
testcase_39 AC 81 ms
84,452 KB
testcase_40 AC 106 ms
96,312 KB
testcase_41 AC 85 ms
86,092 KB
testcase_42 AC 107 ms
96,284 KB
testcase_43 AC 118 ms
100,200 KB
testcase_44 AC 39 ms
53,600 KB
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    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()
    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 sum(ok) == 0:
        print("NO")
    else:
        print("YES")
        ans = []
        for v in range(1, N+1):
            if ok[v]:
                ans.append(v)
                break
        t = 0
        F = [0] * Q
        back = 0
        while t < Q:
            a, b = A[t], B[t]
            v = ans[-1]
            if back == 0:
                t += 1
                if v != a and v != b:
                    if v != 1 and v != N:
                        ans.append(v)
                    elif v == 1:
                        if a != 2 and b != 2:
                            ans.append(2)
                        else:
                            ans.append(1)
                    elif v == N:
                        if a != N-1 and b != N-1:
                            ans.append(N-1)
                        else:
                            ans.append(N)
                else:
                    if v == 1:
                        if a != 2 and b != 2:
                            ans.append(2)
                        else:
                            back = 1
                    elif v == N:
                        if a != N-1 and b != N-1:
                            ans.append(N-1)
                        else:
                            back = 1
                    else:
                        if v-1 != a and v-1 != b and v+1 != a and v+1 != b:
                            if F[t] == 0:
                                ans.append(v-1)
                                F[t] = 1
                            else:
                                ans.append(v+1)
                                F[t] = 0
                        elif v-1 != a and v-1 != b:
                            ans.append(v-1)
                        elif v+1 != a and v+1 != b:
                            ans.append(v+1)
                        else:
                            back = 1
            else:
                ans.pop()
                t -= 1
                if F[t] == 1:
                    back = 0
        print(*ans, sep="\n")


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