結果
| 問題 | No.653 E869120 and Lucky Numbers | 
| コンテスト | |
| ユーザー |  titia | 
| 提出日時 | 2024-07-05 05:13:40 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 32 ms / 2,000 ms | 
| コード長 | 951 bytes | 
| コンパイル時間 | 82 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 10,880 KB | 
| 最終ジャッジ日時 | 2024-07-05 05:13:44 | 
| 合計ジャッジ時間 | 1,925 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 31 | 
ソースコード
import sys
input = sys.stdin.readline
S=list(input().strip())
S.reverse()
while S:
    if S and S[-1]=="6":
        S.pop()
        if S and S[-1]=="1":
            print("No")
            exit()
        continue
    if S[-1]=="7":
        if len(S)==1:
            S.pop()
            continue
        if S[-2]=="6" or S[-2]=="7" or S[-2]=="8":
            S.pop()
            continue
        S.pop()
        S.append("1")
        break
    if S[-1]=="8":
        S.pop()
        S.append("1")
        break
    break
if len(S)==0:
    print("No")
    exit()
while S:
    if len(S)==1:
        print("No")
        exit()
    x=S.pop()
    y=S.pop()
    if x=="1" and y=="2":
        continue
    if x=="1" and (y=="3" or y=="4"):
        if S:
            S.append("1")
            continue
        else:
            continue
    if x=="1" and y=="5":
        S.append("1")
        continue
    print("No")
    exit()
print("Yes")
    
            
            
            
        