結果

問題 No.3092 Tired Queen
ユーザー miya145592
提出日時 2025-04-06 16:03:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 3,783 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 84,188 KB
最終ジャッジ日時 2025-04-06 16:03:56
合計ジャッジ時間 7,695 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N = int(input())
dp = [[0 for _ in range(N)] for _ in range(N)]
now = [0, 0]
dir = [(0, 1), (1, -1), (1, 0), (-1, 1)]
step = 0
for i in range((N+1)//2):
    step += 1
    dp[i][i] = step
    x, y = i, i
    while True:
        idx = (step-1)%4
        dx, dy = dir[idx]
        if idx%2==0:
            nx, ny = x+dx, y+dy
            if i<=nx<N-i and i<=ny<N-i:
                step+=1
                dp[nx][ny] = step
                x, y = nx, ny
            else:
                nx, ny = x+dy, y+dx
                if i<=nx<N-i and i<=ny<N-i:
                    step += 1
                    dp[nx][ny] = step
                    x, y = nx, ny
                else:
                    break
        else:
            nx, ny = y, x
            if x==nx and y==ny:
                break
            step += 1
            dp[nx][ny] = step
            x, y = nx, ny
for d in dp:
    print(*d)
0