問題一覧 > 通常問題

No.401 Number Spiral

レベル : / AI推定難易度 : 500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 374
作問者 : AreTrash / テスター : Tawara
お気に入りにしたユーザー ProblemId : 1218 / 自分の提出
問題文最終更新日: 2019-06-23 23:51:10
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 143 (順位表) の他の問題:

Problem Statement

Output a grid with $N$ rows and $N$ columns in which the numbers from $1$ to $N \times N$ are placed in order along a spiral going toward the center.
The spiral starts at the top-left and initially goes straight to the right. If the next position is outside the grid or has already been visited, it turns in the direction in which it can turn at a right angle.
The following is an example for $N = 3$.

Input

$N$

$N$ is an integer, $1 \le N \le 30$

Output

Output the number spiral with $N$ rows and $N$ columns.
Numbers with 2 or fewer digits must be padded with leading 0s to make them 3 digits.
Separate adjacent numbers with a single-byte space.

Sample

Sample 1
Input
3
Output
001 002 003
008 009 004
007 006 005

Sample 2
Input
4
Output
001 002 003 004
012 013 014 005
011 016 015 006
010 009 008 007

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。