結果

問題 No.1708 Quality of Contest
ユーザー yudedakoyudedako
提出日時 2022-01-25 15:20:33
言語 Scala(Beta)
(3.4.0)
結果
TLE  
実行時間 -
コード長 1,720 bytes
コンパイル時間 9,729 ms
コンパイル使用メモリ 271,352 KB
実行使用メモリ 119,344 KB
最終ジャッジ日時 2024-05-09 15:05:53
合計ジャッジ時間 58,689 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 889 ms
63,584 KB
testcase_01 AC 900 ms
63,624 KB
testcase_02 AC 892 ms
63,756 KB
testcase_03 AC 1,003 ms
64,168 KB
testcase_04 AC 1,032 ms
65,964 KB
testcase_05 AC 1,026 ms
64,428 KB
testcase_06 AC 1,012 ms
64,356 KB
testcase_07 AC 1,023 ms
64,360 KB
testcase_08 AC 888 ms
63,612 KB
testcase_09 AC 1,734 ms
119,344 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.annotation.tailrec
import scala.collection.mutable
import scala.io.StdIn.*


@main def main =
  val Array(n, m, x) = readLine().split(' ').map(_.toInt)
  val problem = Array.fill(n){
    val Array(a, b) = readLine().split(' ').map(_.toInt)
    (a, b - 1)
  }
  val k = readLine().toInt
  val contestant = readLine().split(' ').map(_.toInt)
  val sortedWithQuality = (0 until n).sorted(Ordering.by[Int, Int](problem(_)._1).reverse).toList
  var all = sortedWithQuality
  var newGenre = sortedWithQuality
  val useGenre = Array.fill(m){false}
  val useProblem = Array.fill(n){false}
  val contestantCount = Array.fill(n + 1){0}
  for c <- contestant do
    contestantCount(c) += 1
  var rest = k.toLong - contestantCount(0)
  @tailrec def popNewGenre(rest: List[Int]): List[Int] =
    rest match
      case h::t if useGenre(problem(h)._2) => popNewGenre(t)
      case _ => rest
  @tailrec def popAll(rest: List[Int]): List[Int] =
    rest match
      case h::t if useProblem(h) => popAll(t)
      case _ => rest
  var result = 0L
  for i <- 1 to n do
    newGenre = popNewGenre(newGenre)
    all = popAll(all)
    (newGenre, all) match
      case (Nil, h::t) =>
        useProblem(h) = true
        result += problem(h)._1 * rest
      case (h::t, Nil) =>
        useProblem(h) = true
        useGenre(problem(h)._2) = true
        result += (problem(h)._1 + x) * rest
      case (hi::ti, hj::tj) =>
        if problem(hi)._1 + x < problem(hj)._1 then
          useProblem(hj) = true
          result += problem(hj)._1 * rest
        else
          useProblem(hi) = true
          useGenre(problem(hi)._2) = true
          result += (problem(hi)._1 + x) * rest
    rest -= contestantCount(i)
  println(result)
0