結果

問題 No.401 数字の渦巻き
ユーザー 💕💖💞💕💖💞
提出日時 2017-09-09 15:39:01
言語 Kotlin
(1.9.10)
結果
AC  
実行時間 543 ms / 2,000 ms
コード長 1,552 bytes
コンパイル時間 15,314 ms
コンパイル使用メモリ 427,296 KB
実行使用メモリ 70,056 KB
最終ジャッジ日時 2023-08-12 20:41:00
合計ジャッジ時間 28,491 ms
ジャッジサーバーID
(参考情報)
judge10 / judge9
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 355 ms
54,100 KB
testcase_01 AC 354 ms
54,572 KB
testcase_02 AC 353 ms
54,276 KB
testcase_03 AC 347 ms
54,020 KB
testcase_04 AC 351 ms
54,456 KB
testcase_05 AC 354 ms
54,084 KB
testcase_06 AC 358 ms
54,192 KB
testcase_07 AC 360 ms
54,204 KB
testcase_08 AC 361 ms
54,172 KB
testcase_09 AC 363 ms
54,548 KB
testcase_10 AC 366 ms
54,232 KB
testcase_11 AC 373 ms
54,412 KB
testcase_12 AC 369 ms
54,360 KB
testcase_13 AC 374 ms
54,392 KB
testcase_14 AC 384 ms
54,304 KB
testcase_15 AC 399 ms
54,508 KB
testcase_16 AC 397 ms
54,576 KB
testcase_17 AC 401 ms
54,796 KB
testcase_18 AC 403 ms
54,404 KB
testcase_19 AC 418 ms
56,528 KB
testcase_20 AC 415 ms
56,712 KB
testcase_21 AC 418 ms
56,884 KB
testcase_22 AC 429 ms
56,724 KB
testcase_23 AC 445 ms
58,348 KB
testcase_24 AC 437 ms
58,392 KB
testcase_25 AC 450 ms
58,844 KB
testcase_26 AC 454 ms
58,916 KB
testcase_27 AC 478 ms
60,048 KB
testcase_28 AC 543 ms
69,376 KB
testcase_29 AC 542 ms
70,056 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:11: warning: parameter 'args' is never used
fun main( args : Array<String> ) {
          ^
Main.kt:7:20: warning: parameter 'x' is never used, could be renamed to _
    (0..n-1).map { x ->
                   ^

ソースコード

diff #

fun main( args : Array<String> ) {
  val n = readLine()!!.toInt()
  val mm = mutableListOf<MutableList<Int?>>()

  (0..n-1).map { y ->
    mm.add( mutableListOf<Int?>() )
    (0..n-1).map { x ->
      mm[y].add( null )
    }
  }
  // scan
  
  var sX = 0
  var sY = n-1
  var sX3 = n-1
  var sY3 = 0

  var cnt = 1
  cont@while(true) {
    // 1st
    if ( mm[sX].filter{ it == null } != listOf<Int?>() ) {
      for( i in (0..mm.size-1) ) {
        if( mm[sX][i] == null ) {
          mm[sX][i] = cnt
          cnt++
          continue@cont
        }
      }
    }else if( (0..n-1).map{ mm[it][sY] }.filter { it == null } != listOf<Int?>() ) {
      for( i in (0..n-1) ) {
        if( mm[i][sY] == null ) {
          mm[i][sY] = cnt
          cnt++
          continue@cont
        }
      }
    }else if ( mm[sX3].filter{ it == null } != listOf<Int?>() ) {
      for( i in (mm.size-1 downTo 0) ) {
        if( mm[sX3][i] == null ) {
          mm[sX3][i] = cnt
          cnt++
          continue@cont
        }
      }
    }else if( (0..n-1).map{ mm[it][sY3] }.filter { it == null } != listOf<Int?>() ) {
      for( i in (mm.size-1 downTo 0) ) {
        if( mm[i][sY3] == null ) {
          mm[i][sY3] = cnt
          cnt++
          continue@cont
        }
      }
    } else {
      sX += 1
      sY -= 1
      sX3 -= 1
      sY3 += 1
      if( mm.flatten().filter{ it == null }.size == 0 ) {
        break@cont
      }

    }
  }
  mm.map { y ->
    y.map { x ->
      "%03d".format(x)
    }.joinToString(" ")
    .let {
      println(it)
    }
  }
}
0