結果
問題 | No.401 数字の渦巻き |
ユーザー |
|
提出日時 | 2016-08-02 18:31:56 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 2,205 bytes |
コンパイル時間 | 3,846 ms |
コンパイル使用メモリ | 106,496 KB |
実行使用メモリ | 17,792 KB |
最終ジャッジ日時 | 2024-11-06 23:37:35 |
合計ジャッジ時間 | 2,579 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;class A {static int N;static int[,] Q;static int Dir = 0;static int[] Pos = new int[2];static void Main() {N = int.Parse(Console.ReadLine());Q = new int[N, N];for(int i = 1; i <= N * N; i++) {Q[Pos[0], Pos[1]] = i;Next();}for(int i = 0; i < N; i++) {for(int j = 0; j < N - 1; j++) {Console.Write(string.Format("{0:D3}", Q[j,i]));Console.Write(" ");}Console.Write(string.Format("{0:D3}", Q[N-1,i]));Console.WriteLine();}}static void Next() {switch (Dir) {case 0:if (Pos[0] < N-1) {if (Q[Pos[0] + 1, Pos[1]]!=0) {Dir = 1;Pos[1]++;}else {Pos[0]++;}}else {Dir = 1;Pos[1]++;}break;case 1:if (Pos[1] < N-1) {if (Q[Pos[0], Pos[1] + 1] != 0) {Dir = 2;Pos[0]--;}else {Pos[1]++;}}else {Dir = 2;Pos[0]--;}break;case 2:if (Pos[0] > 0) {if (Q[Pos[0] - 1, Pos[1]] != 0) {Dir = 3;Pos[1]--;}else {Pos[0]--;}}else {Dir = 3;Pos[1]--;}break;case 3:if (Q[Pos[0], Pos[1] - 1] != 0) {Dir = 0;Pos[0]++;}else {Pos[1]--;}break;}}}