結果

問題 No.2373 wa, wo, n
コンテスト
ユーザー nwo
提出日時 2023-06-16 19:00:42
言語 Ruby
(4.0.1)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
AC  
実行時間 1,172 ms / 2,000 ms
コード長 1,148 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 236 ms
コンパイル使用メモリ 9,088 KB
実行使用メモリ 87,936 KB
最終ジャッジ日時 2026-03-23 19:47:21
合計ジャッジ時間 13,077 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

N = gets.to_i
S = gets.chomp

dp = Array.new(N) { Array.new(26, false) }
if S[0] == '?'
  26.times { |j| dp[0][j] = true }
end
if S[0] == 'n'
  dp[0]['n'.ord - 'a'.ord] = true
end
if S[0] == 'w'
  dp[0]['w'.ord - 'a'.ord] = true
end
if S[0] == 'a' || S[0] == 'o'
  puts "No"
  exit
end

1.upto(N - 1) do |i|
  0.upto(25) do |j|
    if dp[i - 1][j]
      if j == 'w'.ord - 'a'.ord
        if S[i] == 'a'
          dp[i]['a'.ord - 'a'.ord] = true
        end
        if S[i] == 'o'
          dp[i]['o'.ord - 'a'.ord] = true
        end
        if S[i] == '?'
          dp[i]['a'.ord - 'a'.ord] = true
          dp[i]['o'.ord - 'a'.ord] = true
        end
      else
        if S[i] == 'w'
          dp[i]['w'.ord - 'a'.ord] = true
        end
        if S[i] == 'n'
          dp[i]['n'.ord - 'a'.ord] = true
        end
        if S[i] == '?'
          dp[i]['w'.ord - 'a'.ord] = true
          dp[i]['n'.ord - 'a'.ord] = true
        end
      end
    end
  end
end

ans = false
ans = true if dp[N - 1]['a'.ord - 'a'.ord]
ans = true if dp[N - 1]['o'.ord - 'a'.ord]
ans = true if dp[N - 1]['n'.ord - 'a'.ord]

if ans
  puts "Yes"
else
  puts "No"
end
0