結果
| 問題 | No.653 E869120 and Lucky Numbers | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 19:52:07 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,500 bytes | 
| コンパイル時間 | 441 ms | 
| コンパイル使用メモリ | 82,408 KB | 
| 実行使用メモリ | 76,216 KB | 
| 最終ジャッジ日時 | 2025-06-12 19:52:47 | 
| 合計ジャッジ時間 | 2,956 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 WA * 1 | 
ソースコード
def main():
    import sys
    p = sys.stdin.read().strip()
    if not p:
        print("No")
        return
    reversed_p = p[::-1]
    
    current_states = set()
    current_states.add((0, False, False))  # (carry, a_ended, b_ended)
    
    for i in range(len(reversed_p)):
        digit = int(reversed_p[i])
        next_states = set()
        for (carry, a_end, b_end) in current_states:
            a_digits = []
            if a_end:
                a_digits.append(0)
            else:
                a_digits.extend([6, 7])
                a_digits.append(0)  # option to end a now
            
            b_digits = []
            if b_end:
                b_digits.append(0)
            else:
                b_digits.extend([6, 7])
                b_digits.append(0)  # option to end b now
            
            for a_d in a_digits:
                for b_d in b_digits:
                    s = a_d + b_d + carry
                    if s % 10 != digit:
                        continue
                    new_c = s // 10
                    new_a_end = a_end or (a_d == 0 and not a_end)
                    new_b_end = b_end or (b_d == 0 and not b_end)
                    next_states.add((new_c, new_a_end, new_b_end))
        current_states = next_states
        if not current_states:
            break
    
    for (carry, a_end, b_end) in current_states:
        if carry == 0:
            print("Yes")
            return
    print("No")
if __name__ == "__main__":
    main()
            
            
            
        