結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー sekiya9311sekiya9311
提出日時 2017-10-01 22:20:38
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,890 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 111,192 KB
実行使用メモリ 26,284 KB
最終ジャッジ日時 2024-04-27 17:36:55
合計ジャッジ時間 1,763 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 22 ms
18,432 KB
testcase_02 AC 22 ms
18,304 KB
testcase_03 AC 20 ms
17,920 KB
testcase_04 AC 20 ms
18,176 KB
testcase_05 AC 20 ms
18,176 KB
testcase_06 AC 20 ms
18,304 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 20 ms
18,176 KB
testcase_14 AC 19 ms
18,176 KB
testcase_15 AC 20 ms
18,176 KB
testcase_16 WA -
testcase_17 AC 20 ms
18,176 KB
testcase_18 AC 21 ms
18,048 KB
testcase_19 AC 21 ms
17,920 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;
using System.Text;
using System.Threading.Tasks;

namespace ProgrammingContest
{
    class MainClass
    {
        Scanner sc;
        static void Main(string[] args)
        {
            new MainClass().Solve();
        }

        const bool DEBUG = false;   // TODO: must check!!
        void Solve()
        {
            if (DEBUG)
            {
                string backPath = "..";
                char dirSep = System.IO.Path.DirectorySeparatorChar;
                string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt";
                sc = new Scanner(new System.IO.StreamReader(inFilePath));
            }
            else
            {
                sc = new Scanner();
            }

            int[,] a = new int[4, 4];
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    a[i, j] = sc.NextInt;
                }
            }
            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    bool ok = false;
                    for (int d = 0; d < 4; d++)
                    {
                        int nx = x + dx[d];
                        int ny = y + dy[d];
                        if (inside(nx, ny) && a[nx, ny] == perfect[x, y])
                        {
                            ok = true;
                            break;
                        }
                    }
                    if (!ok && a[x, y] != perfect[x, y])
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
            }
            Console.WriteLine("Yes");
        }
        int[,] perfect = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 0 } };
        int[] dx = { 0, -1, 0, 1};
        int[] dy = { -1, 0, 1, 0};
        bool inside(int x, int y)
        {
            return 0 <= x && x < 4 && 0 <= y && y < 4;
        }
        bool check(int[,] ar)
        {
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (perfect[i, j] != ar[i, j])
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }

    class Scanner
    {
        Queue<String> buffer;
        char[] sep;
        System.IO.TextReader reader;
        public Scanner(System.IO.TextReader reader = null)
        {
            this.buffer = new Queue<string>();
            this.sep = new char[] { ' ' };
            this.reader = (reader ?? Console.In);
        }
        private void CheckBuffer()
        {
            if (this.buffer.Count == 0)
            {
                String[] sreArray = this.reader.ReadLine().Split(this.sep);
                foreach (String elStr in sreArray)
                {
                    this.buffer.Enqueue(elStr);
                }
            }
        }

        public String Next
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Dequeue();
            }
        }

        public int NextInt
        {
            get
            {
                return int.Parse(this.Next);
            }
        }
        public double NextDouble
        {
            get
            {
                return double.Parse(this.Next);
            }
        }

        public long NextLong
        {
            get
            {
                return long.Parse(this.Next);
            }
        }
        public bool IsEmpty
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Count == 0;
            }
        }
    }
}
0