結果

問題 No.561 東京と京都
ユーザー 💕💖💞💕💖💞
提出日時 2017-09-08 17:37:32
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 959 bytes
コンパイル時間 13,629 ms
コンパイル使用メモリ 455,800 KB
実行使用メモリ 95,008 KB
最終ジャッジ日時 2024-04-30 15:40:57
合計ジャッジ時間 22,113 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 315 ms
60,480 KB
testcase_01 AC 315 ms
95,008 KB
testcase_02 AC 313 ms
57,044 KB
testcase_03 AC 316 ms
56,896 KB
testcase_04 AC 316 ms
57,016 KB
testcase_05 AC 311 ms
57,004 KB
testcase_06 AC 311 ms
57,020 KB
testcase_07 AC 312 ms
57,016 KB
testcase_08 AC 317 ms
57,112 KB
testcase_09 AC 321 ms
56,928 KB
testcase_10 AC 333 ms
56,944 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:4:11: warning: parameter 'args' is never used
fun main( args : Array<String> ) {
          ^
Main.kt:29:35: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Triple<Index /* = Int */, City /* = String */, Money /* = Int */>
  println( memo.maxBy { it.third }!!.third )
                                  ^

ソースコード

diff #

typealias Money = Int
typealias Index = Int
typealias City = String
fun main( args : Array<String> ) {
  val (n, d) = readLine()!!.split(" ").map { it.toInt() }

  val tk = (1..n).map {
    val (t,k) = readLine()!!.split(" ").map { it.toInt() }
    Pair( Pair("T", t), Pair("K", k) )
  }

  val memo = mutableListOf<Triple<Index, City, Money>>( Triple(-1, "T", 0) )
  tk.mapIndexed { i, tk_ ->
    // search lastindex 
    val lasts = memo.filter { it.first == i-1 }
    // build next divercity
    val (tokyo, kyoto) = tk_
    lasts.map { last ->
      if( last.second == tokyo.first ) {
        memo.add( Triple(i, "T", last.third + tokyo.second) )
        memo.add( Triple(i, "K", last.third + kyoto.second - d) )
      }
      if( last.second == kyoto.first ) {
        memo.add( Triple(i, "T", last.third + tokyo.second - d) )
        memo.add( Triple(i, "K", last.third + kyoto.second) )
      }
    }
  }
  println( memo.maxBy { it.third }!!.third )
}
0