結果
| 問題 |
No.2402 Dirty Stairs and Shoes
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:19:17 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 225 ms / 2,000 ms |
| コード長 | 1,896 bytes |
| コンパイル時間 | 160 ms |
| コンパイル使用メモリ | 82,112 KB |
| 実行使用メモリ | 111,264 KB |
| 最終ジャッジ日時 | 2025-03-20 21:20:28 |
| 合計ジャッジ時間 | 5,006 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
import sys
from collections import deque
def main():
n, K = map(int, sys.stdin.readline().split())
m1 = int(sys.stdin.readline())
a_list = list(map(int, sys.stdin.readline().split())) if m1 > 0 else []
dirty = set(a_list)
m2 = int(sys.stdin.readline())
b_list = list(map(int, sys.stdin.readline().split())) if m2 > 0 else []
mat = set(b_list)
# Visited arrays for clean and dirty states
visited_clean = [False] * (n + 1)
visited_dirty = [False] * (n + 1)
queue = deque()
queue.append((0, True))
visited_clean[0] = True
found = False
while queue:
p, is_clean = queue.popleft()
for move in [1, K]:
next_p = p + move
if next_p > n:
continue
# Check if next_p is the target N
if next_p == n:
# The new state is same as current since N is neither dirty nor mat
if is_clean:
found = True
break
else:
continue
else:
# Determine the new state based on next_p's type
if next_p in dirty:
new_clean = False
elif next_p in mat:
new_clean = True
else:
new_clean = is_clean
# Check if this state has been visited before
if new_clean:
if not visited_clean[next_p]:
visited_clean[next_p] = True
queue.append((next_p, new_clean))
else:
if not visited_dirty[next_p]:
visited_dirty[next_p] = True
queue.append((next_p, new_clean))
if found:
break
print("Yes" if found else "No")
if __name__ == "__main__":
main()
lam6er