結果

問題 No.1508 Avoid being hit
ユーザー tamatotamato
提出日時 2021-05-15 00:11:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,453 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 113,892 KB
最終ジャッジ日時 2024-04-10 05:22:10
合計ジャッジ時間 10,228 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 36 ms
52,976 KB
testcase_02 AC 36 ms
52,944 KB
testcase_03 WA -
testcase_04 AC 35 ms
54,240 KB
testcase_05 AC 35 ms
53,536 KB
testcase_06 WA -
testcase_07 AC 36 ms
53,544 KB
testcase_08 AC 36 ms
53,352 KB
testcase_09 AC 36 ms
52,792 KB
testcase_10 AC 35 ms
52,672 KB
testcase_11 AC 38 ms
53,404 KB
testcase_12 AC 36 ms
53,536 KB
testcase_13 AC 37 ms
52,908 KB
testcase_14 AC 36 ms
54,216 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
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 209 ms
108,172 KB
testcase_35 AC 85 ms
84,140 KB
testcase_36 AC 151 ms
99,016 KB
testcase_37 AC 107 ms
89,776 KB
testcase_38 AC 172 ms
103,560 KB
testcase_39 AC 134 ms
94,128 KB
testcase_40 AC 224 ms
108,660 KB
testcase_41 AC 150 ms
99,936 KB
testcase_42 AC 219 ms
108,588 KB
testcase_43 AC 232 ms
112,020 KB
testcase_44 AC 36 ms
53,792 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()
    change = [{} for _ in range(N+1)]
    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:
                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)
                if ok[v-1]:
                    change[v][i+1] = v-1
                elif ok[v+1]:
                    change[v][i+1] = v+1
        for v in st:
            flg = ok[v-1] | ok[v] | ok[v+1]
            if flg:
                ok[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")
        v0 = 0
        for v in range(1, N+1):
            if ok[v]:
                v0 = v
                break
        ans = [v0]
        v = v0
        for t in range(Q):
            if t in change[v]:
                u = change[v][t]
                ans.append(u)
                v = u
            else:
                ans.append(v)
        print(*ans, sep="\n")


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