結果

問題 No.1457 ツブ消ししとるなHard
ユーザー fukafukatanifukafukatani
提出日時 2021-06-23 22:15:23
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,316 ms / 2,000 ms
コード長 851 bytes
コンパイル時間 13,304 ms
コンパイル使用メモリ 268,312 KB
実行使用メモリ 65,256 KB
最終ジャッジ日時 2023-09-07 04:02:13
合計ジャッジ時間 40,424 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,104 ms
63,996 KB
testcase_01 AC 1,061 ms
63,040 KB
testcase_02 AC 1,091 ms
64,148 KB
testcase_03 AC 1,068 ms
63,724 KB
testcase_04 AC 1,221 ms
64,444 KB
testcase_05 AC 1,216 ms
65,256 KB
testcase_06 AC 1,316 ms
64,248 KB
testcase_07 AC 1,170 ms
63,524 KB
testcase_08 AC 1,103 ms
63,100 KB
testcase_09 AC 1,183 ms
64,264 KB
testcase_10 AC 1,164 ms
64,216 KB
testcase_11 AC 1,176 ms
64,244 KB
testcase_12 AC 1,258 ms
63,964 KB
testcase_13 AC 1,184 ms
64,164 KB
testcase_14 AC 1,203 ms
64,432 KB
testcase_15 AC 1,247 ms
64,284 KB
testcase_16 AC 1,209 ms
64,192 KB
testcase_17 AC 1,130 ms
63,188 KB
testcase_18 AC 1,103 ms
64,164 KB
testcase_19 AC 1,258 ms
64,344 KB
testcase_20 AC 1,134 ms
64,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val n, m, x, y, z = sc.nextInt
  val a = List.fill(n)(sc.nextInt).filter(_ > y)

  val init = a.filter(_ >= x).sum
  val init_use = a.count(_ >= x)

  if (init_use > m) {
    println("Handicapped")
  } else {
    val b = a.filter(_ < x)
    val dp = Array.fill(b.size + 1, n * 50 + 1)(0l)
    dp(0)(0) = 1
    for (bnum <- b; prev_used <- b.indices.reverse; prev_sum <- 0 to m * 50 - bnum) {
      dp(prev_used + 1)(prev_sum + bnum) += dp(prev_used )(prev_sum)
    }
    // dp.foreach(s => Console.err.println(s.mkString(" ")))
    val ans = (0 to m - init_use).map(i =>
      if (z * (i + init_use) < init || i >= dp.size || (i == 0 && init_use == 0)) {
        0l
      } else {
        dp(i)(z * (i + init_use) - init)
      }
    ).sum
    println(ans)
  }
}
0