結果

問題 No.1330 Multiply or Divide
ユーザー yuruhiyayuruhiya
提出日時 2021-01-09 15:42:25
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 593 bytes
コンパイル時間 18,923 ms
コンパイル使用メモリ 256,940 KB
実行使用メモリ 33,308 KB
最終ジャッジ日時 2023-09-13 12:57:17
合計ジャッジ時間 22,110 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 133 ms
31,400 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,448 KB
testcase_06 AC 50 ms
30,732 KB
testcase_07 RE -
testcase_08 AC 128 ms
31,356 KB
testcase_09 AC 126 ms
31,612 KB
testcase_10 AC 127 ms
31,724 KB
testcase_11 AC 130 ms
31,372 KB
testcase_12 AC 128 ms
32,256 KB
testcase_13 AC 2 ms
4,412 KB
testcase_14 AC 3 ms
4,408 KB
testcase_15 AC 3 ms
4,456 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,456 KB
testcase_18 AC 135 ms
31,592 KB
testcase_19 AC 135 ms
31,464 KB
testcase_20 AC 134 ms
31,120 KB
testcase_21 AC 135 ms
32,308 KB
testcase_22 AC 135 ms
31,332 KB
testcase_23 AC 138 ms
33,308 KB
testcase_24 AC 2 ms
4,396 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,472 KB
testcase_28 AC 2 ms
4,488 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 3 ms
4,436 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 99 ms
25,920 KB
testcase_35 AC 30 ms
9,888 KB
testcase_36 AC 90 ms
24,320 KB
testcase_37 AC 81 ms
22,828 KB
testcase_38 AC 54 ms
14,116 KB
testcase_39 AC 37 ms
11,072 KB
testcase_40 AC 44 ms
12,564 KB
testcase_41 AC 24 ms
9,136 KB
testcase_42 AC 77 ms
19,608 KB
testcase_43 AC 86 ms
21,756 KB
testcase_44 AC 131 ms
31,560 KB
testcase_45 AC 130 ms
32,752 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 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