結果
問題 | No.217 魔方陣を作ろう |
ユーザー |
![]() |
提出日時 | 2017-05-09 01:40:45 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 25 ms / 5,000 ms |
コード長 | 5,809 bytes |
コンパイル時間 | 1,167 ms |
コンパイル使用メモリ | 106,112 KB |
実行使用メモリ | 17,920 KB |
最終ジャッジ日時 | 2024-09-14 17:44:05 |
合計ジャッジ時間 | 2,518 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Collections;using System.Collections.Generic;using System.Collections.Specialized;using System.Text;using System.Text.RegularExpressions;using System.Linq;using System.IO;class Program{static void Main(string[] args){new Magatro().Solve();}}public class Magatro{private int N;private string[] S;private void Scan(){N = int.Parse(Console.ReadLine());}public void Solve(){Scan();if (N % 2 == 1){int[][] ans = new int[N][];for (int i = 0; i < N; i++){ans[i] = new int[N];}int posY = 0;int posX = N / 2;for (int i = 1; i <= N * N; i++){if (ans[posY][posX] != 0){posY += 2;posY %= N;posX += N - 1;posX %= N;}ans[posY][posX] = i;posY += N - 1;posY %= N;posX++;posX %= N;}for (int i = 0; i < N; i++){Console.WriteLine(string.Join(" ", ans[i]));}}else if (N % 4 == 0){int[][] ans = new int[N][];for (int i = 0; i < N; i++){ans[i] = new int[N];}int cnt = 1;for (int i = 0; i < N; i++){for (int j = 0; j < N; j++){int ii = i % 4;int jj = j % 4;if (ii == 0 || ii == 3){if (jj == 0 || jj == 3){ans[i][j] = cnt;}}if (ii == 1 || ii == 2){if (jj == 1 || jj == 2){ans[i][j] = cnt;}}cnt++;}}cnt = 1;for (int i = N - 1; i >= 0; i--){for (int j = N - 1; j >= 0; j--){if (ans[i][j] == 0){ans[i][j] = cnt;}cnt++;}}for (int i = 0; i < N; i++){Console.WriteLine(string.Join(" ", ans[i]));}}else{int[][] ans = new int[N / 2][];for (int i = 0; i < N / 2; i++){ans[i] = new int[N / 2];}int posY = 0;int posX = N / 4;for (int i = 1; i <= N * N / 4; i++){if (ans[posY][posX] != 0){posY += 2;posY %= N / 2;posX += N / 2 - 1;posX %= N / 2;}ans[posY][posX] = i;posY += N / 2 - 1;posY %= N / 2;posX++;posX %= N / 2;}for (int i = 0; i < N / 2; i++){for (int j = 0; j < N / 2; j++){ans[i][j] = (ans[i][j] - 1) * 4;}}int[][] res = new int[N][];for (int i = 0; i < N; i++){res[i] = new int[N];}char[][] LUX = new char[N / 2][];for (int i = 0; i < N / 2; i++){LUX[i] = new char[N / 2];}for (int i = 0; i < N / 2; i++){for (int j = 0; j < N / 2; j++){if (i == N / 4 + 1){LUX[i][j] = 'U';}else if (i > N / 4 + 1){LUX[i][j] = 'X';}else{LUX[i][j] = 'L';}}}LUX[N / 4][N / 4] = 'U';LUX[N / 4 + 1][N / 4] = 'L';for (int i = 0; i < N / 2; i++){for (int j = 0; j < N / 2; j++){if (LUX[i][j] == 'L'){res[i * 2][j * 2] = ans[i][j] + 4;res[i * 2][j * 2 + 1] = ans[i][j] + 1;res[i * 2 + 1][j * 2] = ans[i][j] + 2;res[i * 2 + 1][j * 2 + 1] = ans[i][j] + 3;}if (LUX[i][j] == 'U'){res[i * 2][j * 2] = ans[i][j] + 1;res[i * 2][j * 2 + 1] = ans[i][j] + 4;res[i * 2 + 1][j * 2] = ans[i][j] + 2;res[i * 2 + 1][j * 2 + 1] = ans[i][j] + 3;}if (LUX[i][j] == 'X'){res[i * 2][j * 2] = ans[i][j] + 1;res[i * 2][j * 2 + 1] = ans[i][j] + 4;res[i * 2 + 1][j * 2] = ans[i][j] + 3;res[i * 2 + 1][j * 2 + 1] = ans[i][j] + 2;}}}for (int i = 0; i < N; i++){Console.WriteLine(string.Join(" ", res[i]));}}}}