結果

問題 No.561 東京と京都
ユーザー 💕💖💞💕💖💞
提出日時 2017-09-08 17:57:30
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,089 bytes
コンパイル時間 14,039 ms
コンパイル使用メモリ 452,164 KB
実行使用メモリ 60,732 KB
最終ジャッジ日時 2024-04-30 15:41:20
合計ジャッジ時間 22,451 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 331 ms
60,428 KB
testcase_01 AC 336 ms
60,332 KB
testcase_02 AC 332 ms
60,428 KB
testcase_03 AC 333 ms
60,284 KB
testcase_04 AC 332 ms
60,528 KB
testcase_05 AC 312 ms
56,932 KB
testcase_06 AC 313 ms
56,948 KB
testcase_07 AC 312 ms
57,000 KB
testcase_08 AC 337 ms
60,532 KB
testcase_09 AC 342 ms
60,720 KB
testcase_10 AC 333 ms
60,504 KB
testcase_11 AC 344 ms
60,672 KB
testcase_12 AC 357 ms
60,652 KB
testcase_13 AC 367 ms
60,612 KB
testcase_14 AC 369 ms
60,652 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 361 ms
60,732 KB
testcase_18 AC 359 ms
60,680 KB
testcase_19 AC 358 ms
60,668 KB
testcase_20 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:4:11: warning: parameter 'args' is never used
fun main( args : Array<String> ) {
          ^
Main.kt:33: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 lastsAll = memo.filter { it.first == i-1 }.sortedBy { it.third * -1 }
    val lasts = when {
      lastsAll.size > 4 -> lastsAll.slice(0..3)
      else -> lastsAll
    }
    // 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