結果
問題 | No.401 数字の渦巻き |
ユーザー | sue_charo |
提出日時 | 2017-08-07 00:01:07 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 1,967 bytes |
コンパイル時間 | 326 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-10-11 23:00:40 |
合計ジャッジ時間 | 2,282 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,880 KB |
testcase_01 | AC | 31 ms
10,880 KB |
testcase_02 | AC | 31 ms
10,880 KB |
testcase_03 | AC | 31 ms
10,880 KB |
testcase_04 | AC | 30 ms
10,880 KB |
testcase_05 | AC | 31 ms
10,880 KB |
testcase_06 | AC | 31 ms
10,880 KB |
testcase_07 | AC | 31 ms
11,008 KB |
testcase_08 | AC | 31 ms
10,880 KB |
testcase_09 | AC | 31 ms
11,008 KB |
testcase_10 | AC | 31 ms
10,880 KB |
testcase_11 | AC | 30 ms
10,880 KB |
testcase_12 | AC | 31 ms
11,008 KB |
testcase_13 | AC | 31 ms
11,008 KB |
testcase_14 | AC | 31 ms
11,008 KB |
testcase_15 | AC | 31 ms
11,008 KB |
testcase_16 | AC | 31 ms
11,008 KB |
testcase_17 | AC | 31 ms
11,008 KB |
testcase_18 | AC | 32 ms
11,008 KB |
testcase_19 | AC | 31 ms
11,008 KB |
testcase_20 | AC | 31 ms
11,008 KB |
testcase_21 | AC | 31 ms
11,136 KB |
testcase_22 | AC | 32 ms
11,008 KB |
testcase_23 | AC | 31 ms
11,008 KB |
testcase_24 | AC | 31 ms
11,136 KB |
testcase_25 | AC | 31 ms
10,880 KB |
testcase_26 | AC | 31 ms
11,008 KB |
testcase_27 | AC | 33 ms
11,008 KB |
testcase_28 | AC | 32 ms
11,008 KB |
testcase_29 | AC | 32 ms
11,008 KB |
ソースコード
# coding: utf-8 INF = 10 ** 20 MOD = 10 ** 9 + 7 def II(): return int(input()) def ILI(): return list(map(int, input().split())) def read(): N = II() return (N,) def solve(N): ans = [[None] * N for __ in range(N)] # [y][x] limit_right = N limit_left = -1 limit_top = 0 limit_bottom = N now_x = 0 now_y = 0 count = 1 state = 0 # 0 : right, 1: down, 2: left, 3: up while count != (N ** 2 + 1): if state == 0: if now_x + 1 == limit_right: limit_right = now_x state = (state + 1) % 4 else: ans[now_y][now_x] = count count += 1 now_x += 1 elif state == 1: if now_y + 1 == limit_bottom: limit_bottom = now_y state = (state + 1) % 4 else: ans[now_y][now_x] = count count += 1 now_y += 1 elif state == 2: if now_x - 1 == limit_left: limit_left = now_x state = (state + 1) % 4 else: ans[now_y][now_x] = count count += 1 now_x -= 1 elif state == 3: if now_y - 1 == limit_top: limit_top = now_y state = (state + 1) % 4 else: ans[now_y][now_x] = count count += 1 now_y -= 1 row_ans = [] for row in ans: for i in range(N): if len(str(row[i])) == 1: row[i] = "00{}".format(row[i]) if len(str(row[i])) == 2: row[i] = "0{}".format(row[i]) if len(str(row[i])) == 3: row[i] = "{}".format(row[i]) row_ans.append(" ".join(row)) ans = "\n".join(row_ans) return ans def main(): params = read() print(solve(*params)) if __name__ == "__main__": main()