結果

問題 No.397 NO MORE KADOMATSU
ユーザー 💕💖💞💕💖💞
提出日時 2018-06-26 19:21:56
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 13,849 ms
コンパイル使用メモリ 423,644 KB
実行使用メモリ 73,584 KB
平均クエリ数 33.17
最終ジャッジ日時 2023-09-23 16:08:40
合計ジャッジ時間 21,804 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 345 ms
72,876 KB
testcase_01 AC 344 ms
73,340 KB
testcase_02 AC 343 ms
72,648 KB
testcase_03 AC 350 ms
72,964 KB
testcase_04 AC 347 ms
73,100 KB
testcase_05 AC 351 ms
72,468 KB
testcase_06 AC 353 ms
73,056 KB
testcase_07 AC 356 ms
73,584 KB
testcase_08 AC 349 ms
73,196 KB
testcase_09 AC 352 ms
72,908 KB
testcase_10 AC 353 ms
73,140 KB
testcase_11 AC 347 ms
72,588 KB
testcase_12 AC 352 ms
72,524 KB
testcase_13 AC 362 ms
72,820 KB
testcase_14 AC 365 ms
72,852 KB
testcase_15 AC 362 ms
72,760 KB
testcase_16 AC 344 ms
72,376 KB
testcase_17 AC 337 ms
72,380 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 -> { println(res.size);  res.map { println("${it.first} ${it.second}") }  }
  }
}
0