結果

問題 No.401 数字の渦巻き
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-06-16 23:09:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 76,968 KB
最終ジャッジ日時 2023-09-06 22:03:01
合計ジャッジ時間 5,038 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
72,688 KB
testcase_01 AC 107 ms
72,788 KB
testcase_02 AC 106 ms
72,596 KB
testcase_03 AC 105 ms
72,804 KB
testcase_04 AC 105 ms
72,624 KB
testcase_05 AC 107 ms
72,648 KB
testcase_06 AC 107 ms
72,800 KB
testcase_07 AC 107 ms
72,804 KB
testcase_08 AC 106 ms
72,640 KB
testcase_09 AC 107 ms
72,640 KB
testcase_10 AC 109 ms
72,936 KB
testcase_11 AC 110 ms
72,864 KB
testcase_12 AC 108 ms
72,800 KB
testcase_13 AC 107 ms
72,752 KB
testcase_14 AC 106 ms
72,936 KB
testcase_15 AC 106 ms
72,508 KB
testcase_16 AC 105 ms
72,804 KB
testcase_17 AC 106 ms
72,592 KB
testcase_18 AC 107 ms
72,932 KB
testcase_19 AC 108 ms
72,828 KB
testcase_20 AC 106 ms
72,756 KB
testcase_21 AC 107 ms
72,864 KB
testcase_22 AC 107 ms
72,716 KB
testcase_23 AC 109 ms
72,836 KB
testcase_24 AC 114 ms
72,880 KB
testcase_25 AC 110 ms
72,932 KB
testcase_26 AC 110 ms
72,700 KB
testcase_27 AC 112 ms
72,592 KB
testcase_28 AC 115 ms
76,968 KB
testcase_29 AC 114 ms
76,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N = int(input())

bef = 0
nxt = [(0,1),(1,0),(0,-1),(-1,0)]
if N==1:
    print('001')
    exit()
A = [[-1]*N for _ in range(N)]

now = 1
nx,ny = 0,0
A[nx][ny] = str(now).zfill(3)
def is_ok(x,y):
    return (0<=x<N)&(0<=y<N)
while True:
    
    flg = True
    now += 1
    while True:
        
        dx,dy = nxt[bef]
        ix,iy = nx+dx,ny+dy
        if not is_ok(ix,iy):
            bef = (bef+1)%4
            continue
        
        if A[ix][iy]!=-1:
            bef = (bef+1)%4
            continue
        A[ix][iy] = str(now).zfill(3)
        nx,ny = ix,iy
        break
    if now == N**2:
        break
    
for i in range(N):
    print(*A[i])
0