結果

問題 No.326 あみだますたー
ユーザー 💕💖💞💕💖💞
提出日時 2017-09-10 15:04:06
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,123 bytes
コンパイル時間 14,204 ms
コンパイル使用メモリ 440,092 KB
実行使用メモリ 86,032 KB
最終ジャッジ日時 2024-04-30 15:52:14
合計ジャッジ時間 34,691 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 349 ms
60,660 KB
testcase_01 WA -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 AC 357 ms
60,452 KB
testcase_06 MLE -
testcase_07 AC 409 ms
60,976 KB
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 WA -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 WA -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 WA -
testcase_21 WA -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 WA -
testcase_27 MLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:11: warning: parameter 'args' is never used
fun main( args : Array<String> ) {
          ^

ソースコード

diff #

fun main( args : Array<String> ) {
  val n = readLine()!!.toInt()
  val k = readLine()!!.toInt()

  val base = (1..n).map { it }.toMutableList()
  (1..k).map {
    val swapPoint = readLine()!!.split(" ").first().toInt() - 1
    val so = base[swapPoint]
    val ta = base[swapPoint+1]
    base[swapPoint] = ta
    base[swapPoint+1] = so
  }
  val ans = readLine()!!.split(" ").mapIndexed { i,it ->
    Pair(it.toInt(), i )
  }
  val ansMap = ans.toMap()
  // here is 直前
  val basePair = base.map {
    Pair(it, ansMap[it]!!)
  }.toMutableList()
  //println( base )
  //println( basePair )

  val swapPoints = mutableListOf<Int>()
  loop@while(true) {
    for( i in (0..basePair.size-2) ) {
      if( basePair[i].second > basePair[i+1].second ) {
        val a1 = basePair[i+1]
        val a2 = basePair[i]
        basePair[i] = a1
        basePair[i+1] = a2
        swapPoints.add( i )
      }
      if( basePair.map { it.second } == basePair.map { it.second }.sortedBy { it } )
        break@loop
    }
  }
  //println( basePair )
  println( swapPoints.size )
  swapPoints.map {
    println("${it + 1} ${it + 2}")
  }
}
0