結果
問題 | No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 |
ユーザー | yudedako |
提出日時 | 2022-01-27 21:08:08 |
言語 | Scala(Beta) (3.4.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,924 bytes |
コンパイル時間 | 16,664 ms |
コンパイル使用メモリ | 268,208 KB |
実行使用メモリ | 98,532 KB |
最終ジャッジ日時 | 2024-11-08 12:21:21 |
合計ジャッジ時間 | 88,470 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,076 ms
64,056 KB |
testcase_01 | AC | 1,126 ms
63,936 KB |
testcase_02 | AC | 1,217 ms
65,200 KB |
testcase_03 | AC | 1,180 ms
64,080 KB |
testcase_04 | AC | 1,204 ms
64,988 KB |
testcase_05 | AC | 1,160 ms
64,400 KB |
testcase_06 | AC | 1,249 ms
64,960 KB |
testcase_07 | AC | 1,222 ms
64,468 KB |
testcase_08 | AC | 1,184 ms
64,984 KB |
testcase_09 | AC | 1,178 ms
65,116 KB |
testcase_10 | AC | 1,204 ms
64,488 KB |
testcase_11 | AC | 1,160 ms
64,760 KB |
testcase_12 | AC | 1,172 ms
64,540 KB |
testcase_13 | AC | 1,170 ms
64,336 KB |
testcase_14 | AC | 1,813 ms
69,948 KB |
testcase_15 | TLE | - |
testcase_16 | AC | 1,974 ms
91,748 KB |
testcase_17 | AC | 1,802 ms
68,712 KB |
testcase_18 | AC | 1,854 ms
80,492 KB |
testcase_19 | AC | 1,870 ms
69,644 KB |
testcase_20 | AC | 1,960 ms
85,728 KB |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | AC | 1,857 ms
71,240 KB |
testcase_24 | TLE | - |
testcase_25 | AC | 1,928 ms
71,224 KB |
testcase_26 | AC | 1,855 ms
70,164 KB |
testcase_27 | AC | 1,804 ms
80,628 KB |
testcase_28 | AC | 1,923 ms
68,364 KB |
testcase_29 | AC | 1,975 ms
67,876 KB |
testcase_30 | TLE | - |
testcase_31 | AC | 1,620 ms
66,360 KB |
testcase_32 | AC | 1,755 ms
67,664 KB |
testcase_33 | AC | 1,801 ms
78,928 KB |
testcase_34 | AC | 978 ms
63,528 KB |
testcase_35 | AC | 1,189 ms
63,836 KB |
testcase_36 | AC | 956 ms
63,452 KB |
testcase_37 | AC | 1,168 ms
63,756 KB |
testcase_38 | AC | 1,265 ms
64,732 KB |
testcase_39 | AC | 1,299 ms
64,656 KB |
testcase_40 | AC | 1,302 ms
64,716 KB |
testcase_41 | AC | 1,309 ms
64,844 KB |
ソースコード
import scala.io.StdIn.readLine import scala.reflect.ClassTag import scala.math.* type Matrix = Array[Array[Option[Long]]] 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(None: Option[Long]){(acc, k) => (acc, left(i)(k).flatMap(l => right(k)(j).map(r => l + r))) match case (Some(a), Some(b)) => Some(max(a, b)) case (None, r) => r case (l, None) => l } } } inline def pow(exp: Int): Matrix = val size = left.length var result = Array.tabulate(size){i => Array.tabulate(size){j => if i == j then Some(0L) else None}} 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.toLong) } val graph = Array.fill(26){Array.tabulate(16){i => Array.tabulate(16){j => if i == j then Some(0L) else None}}} for (s, a, b, e) <- skill do for i <- s.map(_ - 'A') do graph(i)(a)(b) = Some(max(graph(i)(a)(b).getOrElse(e), e)) graph(i)(b)(a) = Some(max(graph(i)(b)(a).getOrElse(e), e)) for i <- 0 until 26 do graph(i) = graph(i).pow(maxCount(i)) var result = Long.MinValue for dest <- 0 until 16 do (0 until 26).foldLeft(Some(0L): Option[Long]){(acc, i) => acc.flatMap{a => graph(i)(initialColor(i))(dest).map(a + _)}} match case Some(sum) => result = max(result, sum) case None => println(if result == Long.MinValue then "Impossible" else result)