結果

問題 No.2463 ストレートフラッシュ
ユーザー simansiman
提出日時 2023-09-11 20:35:51
言語 Ruby
(3.3.0)
結果
AC  
実行時間 926 ms / 2,000 ms
コード長 792 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 11,252 KB
実行使用メモリ 18,000 KB
最終ジャッジ日時 2023-09-11 20:36:06
合計ジャッジ時間 14,377 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,116 KB
testcase_01 AC 79 ms
15,112 KB
testcase_02 AC 79 ms
15,136 KB
testcase_03 AC 81 ms
15,120 KB
testcase_04 AC 83 ms
15,088 KB
testcase_05 AC 83 ms
15,304 KB
testcase_06 AC 79 ms
15,288 KB
testcase_07 AC 82 ms
15,108 KB
testcase_08 AC 83 ms
15,164 KB
testcase_09 AC 86 ms
15,448 KB
testcase_10 AC 81 ms
15,252 KB
testcase_11 AC 80 ms
15,284 KB
testcase_12 AC 81 ms
15,224 KB
testcase_13 AC 650 ms
17,380 KB
testcase_14 AC 721 ms
17,408 KB
testcase_15 AC 696 ms
17,448 KB
testcase_16 AC 754 ms
17,376 KB
testcase_17 AC 841 ms
17,512 KB
testcase_18 AC 926 ms
17,876 KB
testcase_19 AC 917 ms
17,788 KB
testcase_20 AC 902 ms
17,844 KB
testcase_21 AC 880 ms
17,716 KB
testcase_22 AC 909 ms
17,784 KB
testcase_23 AC 917 ms
17,812 KB
testcase_24 AC 892 ms
18,000 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)

memo = Array.new(M + 1) { Array.new(N + 2, Float::INFINITY) }

1.upto(N * M) do |t|
  n, m = gets.split.map(&:to_i)

  if t <= 5
    t = 0
  else
    t -= 5
  end

  memo[m][n] = t if memo[m][n] > t
  if n == 1
    memo[m][N + 1] = t if memo[m][N + 1] > t
  end
end

ans = Float::INFINITY

1.upto(M) do |m|
  1.upto(N - 4) do |n|
    cards = memo[m][n..n + 4].sort
    draw_cnt = 5
    cur = 0
    cnt = 0

    while cards.size > 0
      while cards.size > 0 && cards[0] <= cur
        cards.shift
        draw_cnt -= 1
      end

      if draw_cnt > 0
        next_i = cards[0]
        len = next_i - cur
        c = (len + draw_cnt - 1) / draw_cnt
        cnt += c
        cur += c * draw_cnt
      end
    end

    ans = cnt if ans > cnt
  end
end

puts ans
0