結果

問題 No.2226 Hello, Forgotten World!
ユーザー simansiman
提出日時 2023-02-26 21:00:54
言語 Ruby
(3.3.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 11,300 KB
実行使用メモリ 20,128 KB
最終ジャッジ日時 2023-10-12 11:01:58
合計ジャッジ時間 2,042 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,036 KB
testcase_01 AC 217 ms
20,128 KB
testcase_02 AC 107 ms
15,304 KB
testcase_03 AC 106 ms
15,284 KB
testcase_04 AC 85 ms
15,300 KB
testcase_05 AC 106 ms
15,284 KB
testcase_06 AC 90 ms
15,320 KB
testcase_07 AC 97 ms
15,468 KB
testcase_08 AC 83 ms
15,260 KB
testcase_09 AC 96 ms
15,456 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:41: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:8: warning: assigned but unused variable - best_idx
Syntax OK

ソースコード

diff #

T = gets.to_i

target = 'helloworld'

T.times do
  n = gets.to_i
  s = gets.chomp
  best_idx = -1
  list = []

  (n - 10).downto(0) do |i|
    ok = true
    idx = 0

    while ok && idx < 10
      if target[idx] == s[i + idx] || s[i + idx] == '?'
        # NOOP
      else
        ok = false
      end

      idx += 1
    end

    if ok
      t = s.dup
      10.times do |idx|
        if t[i + idx] == '?'
          t[i + idx] = target[idx]
        end
      end

      t.tr!('?', 'a')
      list << t
    end
  end

  if list.size > 0
    puts list.sort[0]
  else
    puts -1
  end
end
0