結果

問題 No.401 数字の渦巻き
ユーザー kou_kkk
提出日時 2025-01-25 23:28:48
言語 Nim
(2.2.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 690 bytes
コンパイル時間 4,536 ms
コンパイル使用メモリ 66,972 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-25 23:28:59
合計ジャッジ時間 5,513 ms
ジャッジサーバーID
(参考情報)
judge3 / judge10
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils, strutils

let
  n = parseInt stdin.readLine
var
  t = newSeq[string](n).repeat n
  yTop = 1
  xRight, yBottom = n.pred
  xLeft = 0
  direction = 0
  cnt = 1
  x, y = 0

while cnt <= n * n:
  t[y][x] = intToStr(cnt, 3)
  case direction
  of 0:
    if x < xRight:
      x.inc
    else:
      direction.inc
      y.inc
      xRight.dec
  of 1:
    if y < yBottom:
      y.inc
    else:
      direction.inc
      x.dec
      yBottom.dec
  of 2:
    if x > xLeft:
      x.dec
    else:
      direction.inc
      y.dec
      xLeft.inc
  else:
    if y > yTop:
      y.dec
    else:
      direction = 0
      x.inc
      yTop.inc
  cnt.inc
    
for seq1 in t:
  echo seq1.join " "
0