結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2019-05-14 13:16:15 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 711 bytes |
コンパイル時間 | 58 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 6,400 KB |
最終ジャッジ日時 | 2024-07-18 10:48:38 |
合計ジャッジ時間 | 1,386 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
move = [[0, 1], [1, 0], [0, -1], [-1, 0]] N = int(raw_input()) board = [] for i in range(0, N): lst = [] for j in range(0, N): lst.append(0) board.append(lst) now = [0, 0] index = 1 flag = 0 while index <= N*N: board[now[0]][now[1]] = index nextx = now[0]+move[flag][0] nexty = now[1]+move[flag][1] if nextx<0 or N-1<nextx or nexty<0 or N-1<nexty or board[nextx][nexty] != 0: flag = (flag+1)%4 nextx = now[0]+move[flag][0] nexty = now[1]+move[flag][1] now = [nextx, nexty] index += 1 for i in range(0, N): s = '' for j in range(0, N): if len(str(board[i][j])) == 1: s = s + '00' elif len(str(board[i][j])) == 2: s = s + '0' s = s + str(board[i][j]) if j != N-1: s = s + ' ' print s