結果

問題 No.1330 Multiply or Divide
ユーザー yuruhiyayuruhiya
提出日時 2021-01-09 15:47:37
言語 Crystal
(1.11.2)
結果
RE  
実行時間 -
コード長 627 bytes
コンパイル時間 18,529 ms
コンパイル使用メモリ 257,592 KB
実行使用メモリ 33,908 KB
最終ジャッジ日時 2023-09-13 12:57:41
合計ジャッジ時間 22,615 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,392 KB
testcase_01 AC 138 ms
31,484 KB
testcase_02 AC 3 ms
4,436 KB
testcase_03 AC 2 ms
4,400 KB
testcase_04 AC 3 ms
4,384 KB
testcase_05 AC 2 ms
4,492 KB
testcase_06 AC 55 ms
31,824 KB
testcase_07 RE -
testcase_08 AC 133 ms
31,932 KB
testcase_09 AC 131 ms
31,096 KB
testcase_10 AC 134 ms
31,184 KB
testcase_11 AC 135 ms
32,624 KB
testcase_12 AC 132 ms
31,076 KB
testcase_13 AC 3 ms
4,384 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,388 KB
testcase_17 AC 3 ms
4,432 KB
testcase_18 AC 58 ms
31,272 KB
testcase_19 AC 58 ms
31,960 KB
testcase_20 AC 57 ms
31,568 KB
testcase_21 AC 57 ms
31,112 KB
testcase_22 AC 59 ms
31,132 KB
testcase_23 AC 142 ms
33,908 KB
testcase_24 AC 3 ms
4,500 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 3 ms
4,492 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 41 ms
24,488 KB
testcase_35 AC 14 ms
9,712 KB
testcase_36 AC 38 ms
23,668 KB
testcase_37 AC 35 ms
23,228 KB
testcase_38 AC 26 ms
14,132 KB
testcase_39 AC 17 ms
11,100 KB
testcase_40 AC 20 ms
12,520 KB
testcase_41 AC 12 ms
8,600 KB
testcase_42 AC 36 ms
20,408 KB
testcase_43 AC 36 ms
22,132 KB
testcase_44 AC 133 ms
31,116 KB
testcase_45 AC 135 ms
32,196 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
dp = [0] * 64
dp[0] = 1
(0...64).each do |x|
  (0...n).each do |i|
    if dp[x] < goal && x + cnt[i] < 64
      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