結果

問題 No.693 square1001 and Permutation 2
ユーザー 💕💖💞💕💖💞
提出日時 2018-06-14 23:42:54
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 835 bytes
コンパイル時間 11,547 ms
コンパイル使用メモリ 453,436 KB
実行使用メモリ 57,332 KB
最終ジャッジ日時 2024-04-30 18:50:16
合計ジャッジ時間 15,703 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 281 ms
57,088 KB
testcase_01 AC 292 ms
57,108 KB
testcase_02 AC 286 ms
57,156 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 AC 278 ms
57,064 KB
testcase_07 AC 283 ms
56,884 KB
testcase_08 AC 284 ms
57,196 KB
testcase_09 RE -
testcase_10 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args:Array<String>) {
         ^
Main.kt:15:14: warning: variable 'v' is never used
      val (k,v) = it
             ^
Main.kt:19:35: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Triple<Int, Int, Int>
    }.flatten().minBy { it.third }!!
                                  ^

ソースコード

diff #

fun main(args:Array<String>) {
  val n = readLine()!!.toInt()
  val ms = readLine()!!.split(" ").map(String::toInt)
  var targ = (1..n).toSet() - ms.toSet()
  val o = mutableMapOf<Int,Int>()
  ms.map { 
    if( o[it] == null ) o[it] = 0
    o[it] = o[it]!! + 1
  }  
  var o2 = o.toList().filter { it.second > 1 }.toMutableList()

  var result = 0
  while(true) {
    val p = o2.map {
      val (k,v) = it
      targ.map { ta -> 
        Triple(ta, k, Math.abs( ta - k ) )
      }
    }.flatten().minBy { it.third }!!
    //println( p ) 
    targ = targ.filter { it != p.first }.toMutableSet()
    o2 = o2.map { 
      val (k,v) = it
      if( k == p.second ) Pair(k, v-1)
      else Pair(k, v)
    }.filter { it.second > 1 } .toMutableList()
    //println(o2)
    result += p.third
    if( o2.size == 0 ) break
  }
  println(result)
}
0