結果

問題 No.397 NO MORE KADOMATSU
ユーザー 💕💖💞💕💖💞
提出日時 2018-06-26 19:19:22
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 623 bytes
コンパイル時間 14,877 ms
コンパイル使用メモリ 424,748 KB
実行使用メモリ 74,860 KB
平均クエリ数 32.44
最終ジャッジ日時 2023-09-23 16:07:50
合計ジャッジ時間 24,093 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 323 ms
72,988 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 340 ms
73,424 KB
testcase_10 AC 340 ms
73,312 KB
testcase_11 AC 339 ms
72,468 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 334 ms
72,472 KB
testcase_17 AC 325 ms
73,368 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args:Array<String>) {
         ^
Main.kt:2:7: warning: variable 'n' is never used
  val n = readLine()
      ^
Main.kt:6:7: warning: variable 'ans' is never used
  val ans = xs.sorted()
      ^
Main.kt:14:43: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int
    val min = xs.slice(i..xs.size-1).min()!!
                                          ^

ソースコード

diff #

fun main(args:Array<String>) {
  val n = readLine()

  val xs = readLine()!!.split(" ").map( String::toInt ).toMutableList()

  val ans = xs.sorted()

  val res = mutableListOf<Pair<Int,Int>>()
  var i = 0
  while(true) {
    if( i >=  xs.size-1 ) break

    val ta = xs[i]
    val min = xs.slice(i..xs.size-1).min()!!

    if( ta == min ) { i += 1;  continue }

    val tai = xs.slice(i..xs.size-1).lastIndexOf(min) + i
    xs[i]   = min
    xs[tai] = ta

    res.add( Pair(i, tai) )
    i += 1
  }

  //readLine()

  when {
    res.size == 0 -> println(0)
    else -> res.map { println("${it.first} ${it.second}") }
  }
}
0