結果

問題 No.1534 おなかがいたい
ユーザー simansiman
提出日時 2021-06-07 12:31:38
言語 Ruby
(3.3.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 376 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 11,500 KB
実行使用メモリ 28,360 KB
最終ジャッジ日時 2023-08-16 05:10:11
合計ジャッジ時間 4,172 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,100 KB
testcase_01 AC 81 ms
15,292 KB
testcase_02 AC 80 ms
15,236 KB
testcase_03 AC 80 ms
15,052 KB
testcase_04 AC 81 ms
15,128 KB
testcase_05 AC 80 ms
15,052 KB
testcase_06 AC 82 ms
15,340 KB
testcase_07 AC 81 ms
15,200 KB
testcase_08 AC 81 ms
15,324 KB
testcase_09 AC 82 ms
15,172 KB
testcase_10 AC 81 ms
15,136 KB
testcase_11 AC 81 ms
15,036 KB
testcase_12 AC 158 ms
25,680 KB
testcase_13 AC 166 ms
26,752 KB
testcase_14 AC 202 ms
28,360 KB
testcase_15 AC 82 ms
15,616 KB
testcase_16 AC 200 ms
27,472 KB
testcase_17 AC 199 ms
27,620 KB
testcase_18 AC 201 ms
27,368 KB
testcase_19 AC 82 ms
15,652 KB
testcase_20 AC 164 ms
26,948 KB
testcase_21 AC 80 ms
15,120 KB
testcase_22 AC 81 ms
15,128 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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] == 'p' && stack[-2] == 'o'

    if stack.size >= 4 && stack[-4] == 'p' && stack[-3] == 'a' && stack[-2] == 'i'
      if pon_cnt >= 2
        puts pon_cnt - 1
      else
        puts -1
      end
      exit
    end
  end
end

puts -1
0