結果

問題 No.78 クジ付きアイスバー
ユーザー yuruhiyayuruhiya
提出日時 2021-01-05 14:07:09
言語 Crystal
(1.11.2)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 828 bytes
コンパイル時間 19,575 ms
コンパイル使用メモリ 258,380 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-13 12:56:32
合計ジャッジ時間 19,516 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,484 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 3 ms
4,404 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,488 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,436 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,428 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 3 ms
4,460 KB
testcase_26 AC 3 ms
4,492 KB
testcase_27 AC 3 ms
4,504 KB
testcase_28 AC 3 ms
4,384 KB
testcase_29 AC 2 ms
4,416 KB
testcase_30 AC 2 ms
4,408 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 3 ms
4,492 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 3 ms
4,396 KB
testcase_38 AC 2 ms
4,376 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, k = read_line.split.map(&.to_i64)
a = read_line.chars.map(&.to_i)

MAX_B = 32
dp = Array.new(MAX_B) { Array.new(n, 0i64) }

(0...n).each do |start|
  now = 1
  (1..n).each do |cnt|
    i = (start + cnt - 1) % n
    now = now + a[i] - 1
    if now == 0
      dp[0][start] = cnt.to_i64
      break
    elsif cnt == n
      dp[0][start] = k + 1
    end
  end
end

(0...MAX_B - 1).each do |k|
  (0...n).each do |i|
    next_i = (dp[k][i] + i) % n
    dp[k + 1][i] = dp[k][i] + dp[k][next_i]
  end
end

puts (1i64..k).bsearch { |buy|
  ice, now = 0i64, 0
  (0...MAX_B).each { |bit|
    if buy.bit(bit) == 1
      ice += dp[bit][now]
      now = (dp[bit][now] + now) % n
    end
  }
  ice >= k
}
0