結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2016-09-09 00:40:49 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 271 ms / 2,000 ms |
コード長 | 711 bytes |
コンパイル時間 | 4,008 ms |
コンパイル使用メモリ | 77,732 KB |
実行使用メモリ | 59,304 KB |
最終ジャッジ日時 | 2024-11-15 22:54:05 |
合計ジャッジ時間 | 10,241 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();int[][] m = new int[n + 2][n + 2];for (int i = 0; i < n + 2; i++) {m[0][i] = -1;m[n + 1][i] = -1;m[i][0] = -1;m[i][n + 1] = -1;}int k = 1, x = 1, y = 1, tx = 0, ty = 1, tmp;while (k <= n * n) {m[x][y] = k;if (m[x + tx][y + ty] != 0) {tmp = tx;tx = ty;ty = -tmp;}x += tx;y += ty;k++;}for (int i = 1; i < n + 1; i++) {for (int j = 1; j < n + 1; j++) {System.out.printf("%03d", m[i][j]);if (j < n) {System.out.print(" ");}}System.out.println();}}}