結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2016-08-28 19:15:59 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 255 ms / 2,000 ms |
コード長 | 768 bytes |
コンパイル時間 | 2,317 ms |
コンパイル使用メモリ | 77,252 KB |
実行使用メモリ | 56,592 KB |
最終ジャッジ日時 | 2024-11-14 06:27:46 |
合計ジャッジ時間 | 8,837 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
import java.util.Scanner;public class Main {static int INF = 2 << 27;public static void main(String[] args) {Scanner sc = new Scanner(System.in);int N = sc.nextInt();int[][] map = new int[N][N];int x = 0;int y = 0;int v = 0;int[] vx = {1,0,-1,0};int[] vy = {0,1,0,-1};for(int i = 1; i <= N * N; i++) {map[y][x] = i;int tx = x + vx[v];int ty = y + vy[v];if(ty < 0 || tx < 0 || ty >= map.length || tx >= map[ty].length || map[ty][tx] != 0) v = (v + 1) % 4;x = x + vx[v];y = y + vy[v];}for(int i = 0; i < N; i++) {System.out.printf("%03d", map[i][0]);for(int j = 1; j < N; j++) {System.out.printf(" %03d", map[i][j]);}System.out.println();}}}