結果
| 問題 |
No.653 E869120 and Lucky Numbers
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 00:15:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,021 bytes |
| コンパイル時間 | 190 ms |
| コンパイル使用メモリ | 81,544 KB |
| 実行使用メモリ | 78,844 KB |
| 最終ジャッジ日時 | 2025-04-16 00:17:32 |
| 合計ジャッジ時間 | 2,784 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 6 |
ソースコード
from collections import deque
p = input().strip()
digits = list(map(int, reversed(p))) # Process from least significant digit
m = len(digits)
visited = set()
queue = deque()
queue.append((0, 0, False, False))
visited.add((0, 0, False, False))
found = False
while queue:
i, carry_in, a_has, b_has = queue.popleft()
if i == m:
if carry_in == 0 and a_has and b_has:
found = True
break
continue
current_digit = digits[i]
for a_digit in [0, 6, 7]:
for b_digit in [0, 6, 7]:
sum_val = a_digit + b_digit + carry_in
if sum_val % 10 != current_digit:
continue
carry_out = sum_val // 10
new_a_has = a_has or (a_digit != 0)
new_b_has = b_has or (b_digit != 0)
new_state = (i + 1, carry_out, new_a_has, new_b_has)
if new_state not in visited:
visited.add(new_state)
queue.append(new_state)
print("Yes" if found else "No")
lam6er