結果

問題 No.1534 おなかがいたい
ユーザー simansiman
提出日時 2021-06-07 12:28:50
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 339 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 87,016 KB
最終ジャッジ日時 2024-05-03 14:22:52
合計ジャッジ時間 7,091 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
19,108 KB
testcase_01 AC 75 ms
12,288 KB
testcase_02 AC 74 ms
12,160 KB
testcase_03 AC 79 ms
12,416 KB
testcase_04 AC 75 ms
12,160 KB
testcase_05 AC 75 ms
12,160 KB
testcase_06 AC 78 ms
12,160 KB
testcase_07 AC 74 ms
12,160 KB
testcase_08 AC 74 ms
12,288 KB
testcase_09 AC 74 ms
12,288 KB
testcase_10 AC 75 ms
12,160 KB
testcase_11 AC 75 ms
12,160 KB
testcase_12 AC 1,946 ms
60,604 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:16: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:23: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:2: warning: assigned but unused variable - ans
Syntax OK

ソースコード

diff #

S = gets.chomp
ans = 0
stack = []
pon_cnt = 0

S.each_char do |s|
  stack << s

  if s == 'n' && stack.size >= 3
    pon_cnt += 1 if stack[-3..-1].join == 'pon'

    if stack.size >= 4 && stack[-4..-1].join == 'pain'
      if pon_cnt >= 2
        puts pon_cnt - 1
      else
        puts -1
      end
      exit
    end
  end
end

puts -1
0