結果

問題 No.401 数字の渦巻き
ユーザー 💕💖💞💕💖💞
提出日時 2017-09-09 15:39:01
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 591 ms / 2,000 ms
コード長 1,552 bytes
コンパイル時間 15,752 ms
コンパイル使用メモリ 455,892 KB
実行使用メモリ 71,696 KB
最終ジャッジ日時 2024-04-30 15:46:52
合計ジャッジ時間 29,053 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 378 ms
58,056 KB
testcase_01 AC 377 ms
57,952 KB
testcase_02 AC 377 ms
57,992 KB
testcase_03 AC 378 ms
57,972 KB
testcase_04 AC 369 ms
58,108 KB
testcase_05 AC 374 ms
58,044 KB
testcase_06 AC 381 ms
58,048 KB
testcase_07 AC 386 ms
58,156 KB
testcase_08 AC 386 ms
58,032 KB
testcase_09 AC 387 ms
58,056 KB
testcase_10 AC 391 ms
58,056 KB
testcase_11 AC 391 ms
58,068 KB
testcase_12 AC 400 ms
58,036 KB
testcase_13 AC 403 ms
58,168 KB
testcase_14 AC 404 ms
58,208 KB
testcase_15 AC 419 ms
58,296 KB
testcase_16 AC 420 ms
58,148 KB
testcase_17 AC 420 ms
58,160 KB
testcase_18 AC 421 ms
58,160 KB
testcase_19 AC 438 ms
58,376 KB
testcase_20 AC 443 ms
58,444 KB
testcase_21 AC 443 ms
58,240 KB
testcase_22 AC 444 ms
60,568 KB
testcase_23 AC 465 ms
61,988 KB
testcase_24 AC 473 ms
62,076 KB
testcase_25 AC 468 ms
62,076 KB
testcase_26 AC 471 ms
62,140 KB
testcase_27 AC 500 ms
62,848 KB
testcase_28 AC 591 ms
71,696 KB
testcase_29 AC 579 ms
71,536 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