結果

問題 No.240 ナイト散歩
ユーザー nuwasoginuwasogi
提出日時 2015-11-29 00:32:01
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,996 bytes
コンパイル時間 3,746 ms
コンパイル使用メモリ 113,540 KB
実行使用メモリ 27,540 KB
最終ジャッジ日時 2024-09-14 05:01:54
合計ジャッジ時間 3,096 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
25,284 KB
testcase_01 AC 30 ms
27,076 KB
testcase_02 WA -
testcase_03 AC 30 ms
25,248 KB
testcase_04 AC 30 ms
25,392 KB
testcase_05 WA -
testcase_06 AC 30 ms
25,248 KB
testcase_07 AC 30 ms
25,248 KB
testcase_08 AC 31 ms
25,164 KB
testcase_09 AC 31 ms
25,308 KB
testcase_10 AC 30 ms
24,992 KB
testcase_11 AC 30 ms
25,252 KB
testcase_12 AC 30 ms
25,120 KB
testcase_13 AC 31 ms
25,404 KB
testcase_14 AC 30 ms
24,992 KB
testcase_15 AC 31 ms
25,408 KB
testcase_16 AC 30 ms
25,416 KB
testcase_17 AC 30 ms
24,992 KB
testcase_18 AC 30 ms
25,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 32 ms
27,540 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 30 ms
25,128 KB
testcase_29 AC 34 ms
27,104 KB
testcase_30 AC 36 ms
27,292 KB
testcase_31 AC 35 ms
25,252 KB
testcase_32 AC 34 ms
25,308 KB
testcase_33 AC 30 ms
25,140 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 KnightSanpo_CS
{
    class Program
    {
        static void Main(string[] args)
        {
            Solution mysol = new Solution();
            if (mysol.Solve()) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }
    }

    class Solution
    {
        static Vector[] Moves = { new Vector(1, 2), new Vector(2, 1), new Vector(2, -1), new Vector(1, -2), new Vector(-1, -2), new Vector(-2, -1), new Vector(-2, 1), new Vector(-1, 2) };
        Vector Destination;
        static int SDThreshold = 45;

        public bool Solve()
        {
            if (Destination.SquareDistance > SDThreshold || Math.Abs(Destination.X) > 8 || Math.Abs(Destination.Y) > 8)
            {
                return false;
            }
            else if (Destination.SquareDistance <= 1 || Destination.SquareDistance == 5 || Destination.SquareDistance == 20 || Destination.SquareDistance == SDThreshold)
            {
                return true;
            }
            else
            {
                Queue<Vector> q = new Queue<Vector>();
                q.Enqueue(new Vector(0, 0));
                while (q.Count() != 0)
                {
                    Vector loc = q.Dequeue();
                    foreach (Vector m in Moves)
                    {
                        Vector moved = loc + m;
                        moved.n = loc.n + 1;
                        if (moved == Destination)
                        {
                            Console.WriteLine("{0}, {1}, {2}, {3}", loc.X, loc.Y, moved.X, moved.Y);
                            return true;
                        }
                        else
                        {
                            if (!q.Contains(moved) && moved.n <=2)
                            {
                                q.Enqueue(moved);
                            }
                        }
                    }
                }
                return false;
            }
        }

        public Solution()
        {
            int[] xy = ria();
            Destination = new Vector(xy[0], xy[1]);
        }

        static String rs() { return Console.ReadLine(); }
        static int ri() { return int.Parse(Console.ReadLine()); }
        static long rl() { return long.Parse(Console.ReadLine()); }
        static double rd() { return double.Parse(Console.ReadLine()); }
        static String[] rsa() { return Console.ReadLine().Split(' '); }
        static int[] ria() { return Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray(); }
        static long[] rla() { return Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray(); }
        static double[] rda() { return Console.ReadLine().Split(' ').Select(e => double.Parse(e)).ToArray(); }
    }

    struct Vector
    {
        public int X, Y;
        public int n;

        public Vector(int x, int y)
        {
            X = x;
            Y = y;
            n = 0;
        }
        public Vector(Vector a)
        {
            X = a.X;
            Y = a.Y;
            n = a.n;
        }
        public static Vector operator +(Vector a, Vector b)
        {
            Vector c = new Vector(a.X + b.X, a.Y + b.Y);
            return c;
        }
        public static Vector operator -(Vector a, Vector b)
        {
            Vector c = new Vector(a.X - b.X, a.Y - b.Y);
            return c;
        }
        public static Vector operator -(Vector a)
        {
            Vector c = new Vector(-a.X, -a.Y);
            return c;
        }
        public static bool operator ==(Vector a, Vector b)
        {
            return (a.X == b.X && a.Y == b.Y);
        }
        public static bool operator !=(Vector a, Vector b)
        {
            return (a.X != b.X || a.Y != b.Y);
        }
        public int SquareDistance
        {
            get
            {
                return (X * X + Y * Y);
            }
        }
    }
}
0