結果

問題 No.2373 wa, wo, n
ユーザー moharan627
提出日時 2023-07-07 22:36:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,508 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 95,360 KB
最終ジャッジ日時 2024-07-21 18:49:48
合計ジャッジ時間 4,279 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10**9 + 7
MOD2 = 998244353
from collections import defaultdict
def ceil(A,B):
    return -(-A//B)
def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(sys.stdin.readline().rstrip())
    def IC(): return [int(c) for c in sys.stdin.readline().rstrip()]
    def MI(): return map(int, sys.stdin.readline().split())
    N = II()
    S = LC()
    D = [0]*N
    for i in range(N):
        if(S[i]=="w"):
            D[i]=0
        elif(S[i]=="a" or S[i]=="o"):
            D[i]=1
        elif(S[i]=="n"):
            D[i]=2
        elif(S[i]=="?"):
            D[i]=-1
        else:
            print("No")
            exit()
    DP = [[0]*3 for _ in range(N+1)]
    if(S[0]=="?"):
        for i in range(3):
            DP[0][i]=1
    elif(S[0]=="w"):
        DP[0][0]=1
    elif(S[0]=="n"):
        DP[0][2]=1
    #print(DP[0])
    for i in range(1,N):
        if(D[i]==-1):
            DP[i][0] = DP[i-1][1] | DP[i-1][2]
            DP[i][1] = DP[i-1][0]
            DP[i][2] = DP[i-1][1] | DP[i-1][2]
        elif(D[i]==0 or D[i]==2):
            #print(DP[i-1][1],DP[i-1][2],DP[i-1][1] | DP[i-1][2])
            DP[i][D[i]] = DP[i-1][1] | DP[i-1][2]
        elif(D[i]==1):
            DP[i][D[i]] = DP[i - 1][0]
        #print(D[i],DP[i])
    if(DP[N-1][1] or DP[N-1][2]):
        print("Yes")
    else:
        print("No")
    return
solve()
0