結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー nanophoto12nanophoto12
提出日時 2015-12-13 18:32:24
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,938 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 107,112 KB
実行使用メモリ 24,108 KB
最終ジャッジ日時 2023-10-13 14:59:42
合計ジャッジ時間 4,575 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 66 ms
21,960 KB
testcase_02 WA -
testcase_03 AC 65 ms
22,004 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 66 ms
21,888 KB
testcase_12 WA -
testcase_13 AC 65 ms
21,928 KB
testcase_14 AC 64 ms
21,852 KB
testcase_15 AC 64 ms
22,028 KB
testcase_16 AC 64 ms
21,848 KB
testcase_17 AC 67 ms
24,004 KB
testcase_18 AC 64 ms
21,888 KB
testcase_19 AC 65 ms
23,912 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

namespace No228
{
	class MainClass
	{
		private static Tuple<int,int> FindZero(List<int> values)
		{
			for (int i = 0; i < values.Count; i++) {
				if (values [i] == 0) {
					return new Tuple<int, int>(i %4, i / 4);
				}
			}
			throw new Exception ();
		}
			
		private static bool IsNear(int expected, int[] values)
		{
			var y = (expected-1) / 4;
			var x = (expected-1) % 4;
			var shifts = new []{ 
				new Tuple<int,int> (0, 0),
				new Tuple<int,int> (1, 0),
				new Tuple<int,int> (-1, 0),
				new Tuple<int,int> (0, 1),
				new Tuple<int,int> (0, -1),
			};
			foreach (var element in shifts) {
				var cx = x + element.Item1;
				var cy = y + element.Item2;
				if (cx >= 0 && cx < 4) {
					if (cy >= 0 && cy < 4) {
						if (values [cy * 4 + cx] == expected) {
							return true;
						}
					}						
				}
			}
			return false;
		}

		public static void Main (string[] args)
		{
			List<int> list = new List<int> ();
			for (int i = 0; i < 4; i++) {
				var line = Console.ReadLine ().Split(' ').Select(value=>Convert.ToInt32(value));
				list.AddRange (line);
			}
			var initial = Enumerable.Range (1, 15).Concat (new[]{ 0 }).ToList ();
			for (int y = 0; y < 4; y++) {
				for (int x = 0; x < 4; x++) {
					var index = y * 4 + x;
					if (list [index] != 0) {
						if(!IsNear(initial[index], list.ToArray())){
							Console.WriteLine ("No");
							return;
						}							
					}
				}
			}
			int swapCount = 0;
			for (int y = 0; y < 4; y++) {
				for (int x = 0; x < 4; x++) {
					var index = y * 4 + x;
					if (list [index] != 0) {
						if (list [index] != initial [index]) {
							swapCount++;
						}
					}
				}
			}
			var point = FindZero (list);
			swapCount += (3 - point.Item1);
			swapCount += (3 - point.Item2);

			if (swapCount % 2 == 0) {
				Console.WriteLine ("Yes");
				return;
			}
			Console.WriteLine ("No");
		}
	}
}
0