結果
問題 | No.240 ナイト散歩 |
ユーザー | nuwasogi |
提出日時 | 2015-11-29 00:33:20 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 3,895 bytes |
コンパイル時間 | 2,693 ms |
コンパイル使用メモリ | 112,152 KB |
実行使用メモリ | 27,544 KB |
最終ジャッジ日時 | 2024-10-07 21:16:24 |
合計ジャッジ時間 | 4,692 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
25,120 KB |
testcase_01 | AC | 30 ms
27,320 KB |
testcase_02 | AC | 33 ms
27,340 KB |
testcase_03 | AC | 29 ms
25,120 KB |
testcase_04 | AC | 31 ms
27,184 KB |
testcase_05 | AC | 32 ms
25,136 KB |
testcase_06 | AC | 29 ms
25,380 KB |
testcase_07 | AC | 30 ms
25,252 KB |
testcase_08 | AC | 30 ms
25,392 KB |
testcase_09 | AC | 30 ms
27,444 KB |
testcase_10 | AC | 30 ms
27,444 KB |
testcase_11 | AC | 31 ms
27,200 KB |
testcase_12 | AC | 29 ms
25,120 KB |
testcase_13 | AC | 30 ms
25,248 KB |
testcase_14 | AC | 30 ms
25,380 KB |
testcase_15 | AC | 30 ms
25,128 KB |
testcase_16 | AC | 30 ms
25,024 KB |
testcase_17 | AC | 30 ms
27,180 KB |
testcase_18 | AC | 30 ms
25,376 KB |
testcase_19 | AC | 32 ms
25,300 KB |
testcase_20 | AC | 33 ms
27,352 KB |
testcase_21 | AC | 29 ms
23,220 KB |
testcase_22 | AC | 32 ms
25,436 KB |
testcase_23 | AC | 32 ms
25,248 KB |
testcase_24 | AC | 33 ms
27,544 KB |
testcase_25 | AC | 32 ms
25,244 KB |
testcase_26 | AC | 33 ms
25,392 KB |
testcase_27 | AC | 33 ms
25,520 KB |
testcase_28 | AC | 29 ms
25,264 KB |
testcase_29 | AC | 32 ms
23,348 KB |
testcase_30 | AC | 33 ms
27,352 KB |
testcase_31 | AC | 32 ms
25,388 KB |
testcase_32 | AC | 33 ms
25,380 KB |
testcase_33 | AC | 30 ms
25,376 KB |
コンパイルメッセージ
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 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) { 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); } } } }