結果

問題 No.989 N×Mマス計算(K以上)
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-02-14 22:25:48
言語 Ruby
(3.3.0)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 680 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 19,664 KB
最終ジャッジ日時 2024-04-16 02:36:25
合計ジャッジ時間 4,647 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
12,160 KB
testcase_01 AC 88 ms
12,160 KB
testcase_02 AC 87 ms
12,160 KB
testcase_03 AC 87 ms
12,160 KB
testcase_04 AC 90 ms
12,160 KB
testcase_05 AC 91 ms
12,160 KB
testcase_06 AC 91 ms
12,160 KB
testcase_07 AC 88 ms
12,288 KB
testcase_08 AC 88 ms
12,160 KB
testcase_09 AC 90 ms
12,416 KB
testcase_10 AC 217 ms
15,360 KB
testcase_11 AC 194 ms
18,432 KB
testcase_12 AC 230 ms
18,292 KB
testcase_13 AC 135 ms
17,408 KB
testcase_14 AC 280 ms
19,664 KB
testcase_15 AC 147 ms
13,312 KB
testcase_16 AC 163 ms
15,104 KB
testcase_17 AC 131 ms
17,280 KB
testcase_18 AC 186 ms
12,928 KB
testcase_19 AC 171 ms
18,560 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:24: warning: assigned but unused variable - m
Syntax OK

ソースコード

diff #

def find(a, target)
  min_i, max_i = 0, a.size - 1

  return a.size if target < a[min_i]
  return 0 if target > a[max_i]

  mid_i = (max_i + min_i) / 2
  while min_i != max_i
    # puts "min_i = #{min_i}, max_i = #{max_i}"
    if target <= a[mid_i]
      break if max_i == mid_i
      max_i = mid_i
    else
      break if min_i == mid_i
      min_i = mid_i
    end

    mid_i = (max_i + min_i) / 2
  end

  a.size - max_i
end

n, m, k = gets.chomp.split.map(&:to_i)

b = gets.chomp.split
op = b.shift
a = [] * n
b.map!(&:to_i)
n.times do
  a << gets.chomp.to_i
end
b.sort!

ans = 0
a.each do |ai|
  target = op == '+' ? k - ai : k / ai.to_f

  ans += find(b, target)
end
puts ans
0