結果
| 問題 | No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-01-27 20:58:25 | 
| 言語 | Scala(Beta) (3.6.2) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,716 bytes | 
| コンパイル時間 | 14,504 ms | 
| コンパイル使用メモリ | 270,504 KB | 
| 実行使用メモリ | 96,004 KB | 
| 最終ジャッジ日時 | 2024-12-26 02:28:17 | 
| 合計ジャッジ時間 | 77,249 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 39 WA * 3 | 
ソースコード
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, if left(i)(k) == MinValue || right(k)(j) == MinValue then MinValue else (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)
            
            
            
        