結果

問題 No.2402 Dirty Stairs and Shoes
ユーザー Theta
提出日時 2023-10-13 17:15:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,322 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 107,136 KB
最終ジャッジ日時 2024-09-15 13:11:28
合計ジャッジ時間 3,918 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N, K = map(int, input().split())
    M1 = int(input())
    dirty = set(map(int, input().split()))
    M2 = int(input())
    mats = set(map(int, input().split()))
    dp_table = [[0, 0] for _ in range(N + 1)]
    dp_table[0][0] = 1
    for stair_idx in range(N):
        if stair_idx + 1 in dirty:
            dp_table[stair_idx +
                     1][1] |= dp_table[stair_idx][0] | dp_table[stair_idx][1]
        elif stair_idx + 1 in mats:
            dp_table[stair_idx +
                     1][0] |= dp_table[stair_idx][0] | dp_table[stair_idx][1]
        else:
            dp_table[stair_idx + 1][0] |= dp_table[stair_idx][0]
            dp_table[stair_idx + 1][1] |= dp_table[stair_idx][1]
        if stair_idx + K > N:
            continue
        if stair_idx + K in dirty:
            dp_table[stair_idx +
                     K][1] |= dp_table[stair_idx][0] | dp_table[stair_idx][1]
        elif stair_idx + K in mats:
            dp_table[stair_idx +
                     K][0] |= dp_table[stair_idx][0] | dp_table[stair_idx][1]
        else:
            dp_table[stair_idx + K][0] |= dp_table[stair_idx][0]
            dp_table[stair_idx + K][1] |= dp_table[stair_idx][1]

    if dp_table[N][0] > 0:
        print("Yes")
    else:
        print("No")


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