結果
問題 | No.2373 wa, wo, n |
ユーザー | McGregorsh |
提出日時 | 2023-07-07 22:00:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 246 ms / 2,000 ms |
コード長 | 2,700 bytes |
コンパイル時間 | 610 ms |
コンパイル使用メモリ | 82,528 KB |
実行使用メモリ | 120,648 KB |
最終ジャッジ日時 | 2024-07-21 18:00:35 |
合計ジャッジ時間 | 9,048 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 39 |
ソースコード
import sys from sys import stdin from fractions import Fraction import math from math import ceil, floor, sqrt, pi, factorial, gcd from copy import deepcopy from collections import Counter, deque, defaultdict from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement, permutations from bisect import bisect, bisect_left, bisect_right from functools import reduce, lru_cache from decimal import Decimal, getcontext, ROUND_HALF_UP def i_input(): return int(stdin.readline()) def i_map(): return map(int, stdin.readline().split()) def i_list(): return list(i_map()) def s_input(): return stdin.readline()[:-1] def s_map(): return s_input().split() def s_list(): return list(s_map()) def lcm(a, b): return a * b // gcd(a, b) def get_distance(x1, y1, x2, y2): d = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) return d def rotate(table): n_fild = [] for x in zip(*table[::-1]): n_fild.append(x) return n_fild sys.setrecursionlimit(10 ** 7) INF = float('inf') MOD = 10 ** 9 + 7 MOD2 = 998244353 alpa = 'abcdefghijklmnopqrstuvwxyz' ALPA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def main(): N = int(input()) S = list(input()) dp = [[False] * 5 for i in range(N)] if S[0] == 'w': dp[0][0] = True if S[0] == 'n': dp[0][3] = True if S[0] == '?': dp[0][4] = True for i in range(1, N): p = S[i] if p == 'w': if dp[i-1][1]: dp[i][0] = True if dp[i-1][2]: dp[i][0] = True if dp[i-1][3]: dp[i][0] = True if dp[i-1][4]: dp[i][0] = True if p == 'a': if dp[i-1][0]: dp[i][1] = True if dp[i-1][4]: dp[i][1] = True if p == 'o': if dp[i-1][0]: dp[i][2] = True if dp[i-1][4]: dp[i][2] = True if p == 'n': if dp[i-1][1]: dp[i][3] = True if dp[i-1][2]: dp[i][3] = True if dp[i-1][3]: dp[i][3] = True if dp[i-1][4]: dp[i][3] = True if p == '?': if dp[i-1][0]: dp[i][1] = True dp[i][2] = True if dp[i-1][1]: dp[i][4] = True if dp[i-1][2]: dp[i][4] = True if dp[i-1][3]: dp[i][4] = True if dp[i-1][4]: dp[i][4] = True juge = 'waon?' if p not in juge: print('No') exit() for i in range(1, 5): if dp[-1][i]: print('Yes') exit() print('No') if __name__ == '__main__': main()