結果
| 問題 |
No.228 ゆきこちゃんの 15 パズル
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2015-12-13 18:32:24 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,938 bytes |
| コンパイル時間 | 4,170 ms |
| コンパイル使用メモリ | 107,776 KB |
| 実行使用メモリ | 19,200 KB |
| 最終ジャッジ日時 | 2024-09-15 11:45:24 |
| 合計ジャッジ時間 | 2,863 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 8 WA * 9 |
コンパイルメッセージ
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.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");
}
}
}
nanophoto12