結果

問題 No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木
ユーザー yudedakoyudedako
提出日時 2022-01-27 20:53:41
言語 Scala(Beta)
(3.4.0)
結果
WA  
実行時間 -
コード長 1,642 bytes
コンパイル時間 14,258 ms
コンパイル使用メモリ 258,356 KB
実行使用メモリ 94,720 KB
最終ジャッジ日時 2023-08-26 22:47:10
合計ジャッジ時間 76,576 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,076 ms
62,664 KB
testcase_01 AC 1,132 ms
62,536 KB
testcase_02 AC 1,138 ms
63,016 KB
testcase_03 AC 1,167 ms
63,184 KB
testcase_04 AC 1,187 ms
62,916 KB
testcase_05 AC 1,176 ms
62,344 KB
testcase_06 AC 1,176 ms
63,100 KB
testcase_07 AC 1,182 ms
62,704 KB
testcase_08 AC 1,189 ms
62,748 KB
testcase_09 AC 1,167 ms
62,828 KB
testcase_10 AC 1,170 ms
62,920 KB
testcase_11 WA -
testcase_12 AC 1,180 ms
62,344 KB
testcase_13 AC 1,170 ms
63,136 KB
testcase_14 AC 1,589 ms
65,668 KB
testcase_15 AC 1,778 ms
87,400 KB
testcase_16 AC 1,757 ms
87,544 KB
testcase_17 AC 1,560 ms
65,500 KB
testcase_18 AC 1,671 ms
75,972 KB
testcase_19 AC 1,587 ms
65,588 KB
testcase_20 AC 1,643 ms
77,596 KB
testcase_21 AC 1,792 ms
94,176 KB
testcase_22 AC 1,788 ms
94,228 KB
testcase_23 AC 1,583 ms
67,692 KB
testcase_24 AC 1,799 ms
94,720 KB
testcase_25 AC 1,584 ms
67,592 KB
testcase_26 AC 1,569 ms
65,540 KB
testcase_27 AC 1,652 ms
75,984 KB
testcase_28 AC 1,568 ms
63,968 KB
testcase_29 AC 1,556 ms
63,688 KB
testcase_30 AC 1,782 ms
92,176 KB
testcase_31 AC 1,291 ms
62,960 KB
testcase_32 AC 1,539 ms
63,512 KB
testcase_33 AC 1,618 ms
76,492 KB
testcase_34 AC 978 ms
62,516 KB
testcase_35 AC 1,206 ms
62,704 KB
testcase_36 AC 984 ms
62,952 KB
testcase_37 AC 1,182 ms
62,588 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 1,240 ms
62,656 KB
testcase_41 AC 1,230 ms
62,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.io.StdIn.readLine
import scala.reflect.ClassTag
import scala.math.*
type Matrix = Array[Array[Long]]

inline val MinValue = 26 * 15 * -1000000L - 1
extension (left: Matrix)
  inline def *(right: Matrix): Matrix =
    val row = left.length
    val column = right(0).length
    val mid = right.length
    Array.tabulate(row){i =>
      Array.tabulate(column){j =>
        (0 until mid).foldLeft(MinValue){(acc, k) => max(acc, left(i)(k) + right(k)(j))}
      }
    }
  inline def pow(exp: Int): Matrix =
    val size = left.length
    var result = Array.tabulate(size){i => Array.tabulate(size){j => if i == j then 0L else MinValue}}
    var base = left
    var e = exp
    while e > 0 do
      if (e & 1) == 1 then
        result *= base
      base *= base
      e >>= 1
    result

@main def main =
  val initialColor = readLine().split(' ').map(_.toInt - 1)
  val maxCount = readLine().split(' ').map(_.toInt)
  val n = readLine().toInt
  val skill = Array.fill(n){
    val Array(s, a, b, e) = readLine().split(' ')
    (s, a.toInt - 1, b.toInt - 1, e.toInt)
  }
  val graph = Array.fill(26){Array.tabulate(16){i => Array.tabulate(16){j => if i == j then 0L else MinValue}}}
  for (s, a, b, e) <- skill do
    for i <- s.map(_ - 'A') do
      graph(i)(a)(b) = max(graph(i)(a)(b), e)
      graph(i)(b)(a) = max(graph(i)(b)(a), e)
  for i <- 0 until 26 do
    graph(i) = graph(i).pow(maxCount(i))
  var result = MinValue
  for dest <- 0 until 16 do
    var sum = 0L
    for i <- 0 until 26 do
      sum += graph(i)(initialColor(i))(dest)
    result = max(result, sum)
  println(if result == MinValue then "Impossible" else result)
0