結果

問題 No.1330 Multiply or Divide
ユーザー yuruhiyayuruhiya
提出日時 2021-01-09 15:50:26
言語 Crystal
(1.10.0)
結果
AC  
実行時間 743 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 17,045 ms
コンパイル使用メモリ 258,136 KB
実行使用メモリ 33,520 KB
最終ジャッジ日時 2023-09-13 12:58:10
合計ジャッジ時間 26,704 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 700 ms
31,444 KB
testcase_02 AC 3 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 50 ms
31,428 KB
testcase_07 AC 743 ms
31,460 KB
testcase_08 AC 698 ms
31,084 KB
testcase_09 AC 695 ms
32,072 KB
testcase_10 AC 696 ms
31,332 KB
testcase_11 AC 700 ms
32,252 KB
testcase_12 AC 701 ms
31,432 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,384 KB
testcase_15 AC 3 ms
4,424 KB
testcase_16 AC 2 ms
4,504 KB
testcase_17 AC 2 ms
4,440 KB
testcase_18 AC 55 ms
31,072 KB
testcase_19 AC 53 ms
31,272 KB
testcase_20 AC 56 ms
31,800 KB
testcase_21 AC 54 ms
31,364 KB
testcase_22 AC 56 ms
32,004 KB
testcase_23 AC 706 ms
33,520 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,476 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,408 KB
testcase_29 AC 3 ms
4,440 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,412 KB
testcase_32 AC 2 ms
4,400 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 40 ms
24,876 KB
testcase_35 AC 14 ms
9,820 KB
testcase_36 AC 36 ms
23,808 KB
testcase_37 AC 34 ms
22,576 KB
testcase_38 AC 24 ms
14,200 KB
testcase_39 AC 17 ms
11,192 KB
testcase_40 AC 19 ms
12,516 KB
testcase_41 AC 12 ms
8,612 KB
testcase_42 AC 33 ms
19,668 KB
testcase_43 AC 36 ms
22,152 KB
testcase_44 AC 699 ms
31,072 KB
testcase_45 AC 699 ms
31,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

n, m, k = read_line.split.map(&.to_i64)
a = read_line.split.map(&.to_i64)
b, cnt = a.map { |i|
  c = 1
  while i % k == 0
    i //= k
    c += 1
  end
  [i, c]
}.transpose

if a.max > m
  puts 1
  exit
end

if b.max == 1
  puts -1
  exit
end

goal = m // a.max + 1
MAX_X = 500
dp = [0] * MAX_X
dp[0] = 1
(0...MAX_X).each do |x|
  (0...n).each do |i|
    if dp[x] < goal && x + cnt[i] < MAX_X
      dp[x + cnt[i]] = {dp[x + cnt[i]], dp[x] * b[i]}.max
    end
  end
end
puts dp.index { |i| i >= goal }.not_nil! + 1
0