結果

問題 No.1457 ツブ消ししとるなHard
ユーザー yuruhiyayuruhiya
提出日時 2021-03-31 21:42:24
言語 Crystal
(1.11.2)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 731 bytes
コンパイル時間 20,609 ms
コンパイル使用メモリ 254,768 KB
実行使用メモリ 6,896 KB
最終ジャッジ日時 2023-08-22 00:16:51
合計ジャッジ時間 21,934 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,444 KB
testcase_01 AC 3 ms
4,384 KB
testcase_02 AC 2 ms
4,400 KB
testcase_03 AC 2 ms
4,412 KB
testcase_04 AC 21 ms
5,788 KB
testcase_05 AC 22 ms
6,896 KB
testcase_06 AC 22 ms
5,656 KB
testcase_07 AC 3 ms
4,428 KB
testcase_08 AC 2 ms
4,476 KB
testcase_09 AC 6 ms
5,872 KB
testcase_10 AC 6 ms
5,792 KB
testcase_11 AC 3 ms
4,500 KB
testcase_12 AC 21 ms
6,284 KB
testcase_13 AC 6 ms
5,824 KB
testcase_14 AC 6 ms
5,712 KB
testcase_15 AC 9 ms
5,840 KB
testcase_16 AC 20 ms
6,296 KB
testcase_17 AC 3 ms
4,488 KB
testcase_18 AC 2 ms
4,416 KB
testcase_19 AC 16 ms
5,852 KB
testcase_20 AC 2 ms
4,536 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, x, y, z = read_line.split.map(&.to_i)
a = read_line.split.map(&.to_i)
if a.count { |i| i >= x } > m
  puts "Handicapped"
  exit
end

sum = a.sum
dp = Array.new(-~n) { [0i64] * -~sum }
dp[0][0] = 1i64
a.each do |val|
  dp2 = Array.new(-~n) { [0i64] * -~sum }
  (0...n).reverse_each { |i|
    (0...sum).reverse_each { |j|
      dp2[i + 1][j + val] += dp[i][j] if val > y && dp[i][j] > 0
      dp2[i][j] += dp[i][j] if val < x && dp[i][j] > 0
    }
  }
  dp = dp2.dup
end

ans = 0i64
(0..n).each { |i|
  (0..sum).each { |j|
    ans += dp[i][j] if i * z == j && i <= m && i != 0
  }
}
puts ans
0