結果

問題 No.397 NO MORE KADOMATSU
ユーザー 💕💖💞💕💖💞
提出日時 2018-06-26 19:16:39
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 621 bytes
コンパイル時間 15,097 ms
コンパイル使用メモリ 425,604 KB
実行使用メモリ 126,980 KB
最終ジャッジ日時 2023-09-23 16:07:25
合計ジャッジ時間 22,063 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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