結果

問題 No.145 yukiover
ユーザー simansiman
提出日時 2022-02-23 17:35:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,063 ms / 5,000 ms
コード長 520 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 11,388 KB
実行使用メモリ 27,352 KB
最終ジャッジ日時 2023-09-14 10:23:47
合計ジャッジ時間 10,282 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,160 KB
testcase_01 AC 81 ms
15,304 KB
testcase_02 AC 82 ms
15,248 KB
testcase_03 AC 81 ms
15,048 KB
testcase_04 AC 81 ms
15,048 KB
testcase_05 AC 82 ms
15,004 KB
testcase_06 AC 82 ms
15,300 KB
testcase_07 AC 81 ms
15,056 KB
testcase_08 AC 81 ms
15,132 KB
testcase_09 AC 81 ms
15,120 KB
testcase_10 AC 82 ms
15,132 KB
testcase_11 AC 127 ms
22,736 KB
testcase_12 AC 544 ms
24,764 KB
testcase_13 AC 384 ms
24,824 KB
testcase_14 AC 718 ms
25,484 KB
testcase_15 AC 843 ms
27,352 KB
testcase_16 AC 1,063 ms
26,408 KB
testcase_17 AC 797 ms
26,152 KB
testcase_18 AC 612 ms
25,108 KB
testcase_19 AC 699 ms
25,484 KB
testcase_20 AC 683 ms
25,736 KB
testcase_21 AC 508 ms
25,028 KB
testcase_22 AC 613 ms
25,268 KB
testcase_23 AC 229 ms
25,192 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
S = gets.chomp.chars.sort.reverse
T = 'yuki'

def f(x)
  completed = Array.new(x, false)
  idx = 0

  5.times do |i|
    x.times do |j|
      next if completed[j]
      return false if N <= idx

      if i == 4 || T[i] < S[idx]
        completed[j] = true
      elsif T[i] == S[idx]
        # NOOP
      else
        return false
      end

      idx += 1
    end
  end

  true
end

ok = 0
ng = N + 1

while (ok - ng).abs >= 2
  x = (ok + ng) / 2

  if f(x)
    ok = x
  else
    ng = x
  end
end

puts ok
0