結果

問題 No.367 ナイトの転身
ユーザー AreTrashAreTrash
提出日時 2016-05-03 19:37:58
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,409 bytes
コンパイル時間 1,123 ms
コンパイル使用メモリ 106,880 KB
実行使用メモリ 26,132 KB
最終ジャッジ日時 2024-04-15 10:44:29
合計ジャッジ時間 3,791 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
18,048 KB
testcase_01 AC 32 ms
18,048 KB
testcase_02 AC 29 ms
17,920 KB
testcase_03 AC 33 ms
17,792 KB
testcase_04 AC 33 ms
17,920 KB
testcase_05 WA -
testcase_06 AC 33 ms
18,304 KB
testcase_07 AC 33 ms
18,048 KB
testcase_08 AC 29 ms
18,176 KB
testcase_09 WA -
testcase_10 AC 169 ms
24,704 KB
testcase_11 AC 231 ms
25,472 KB
testcase_12 AC 118 ms
23,168 KB
testcase_13 AC 107 ms
22,656 KB
testcase_14 AC 109 ms
22,784 KB
testcase_15 AC 32 ms
19,200 KB
testcase_16 AC 99 ms
22,528 KB
testcase_17 AC 40 ms
21,504 KB
testcase_18 AC 46 ms
22,016 KB
testcase_19 AC 54 ms
22,312 KB
testcase_20 AC 42 ms
22,144 KB
testcase_21 AC 54 ms
21,880 KB
testcase_22 AC 30 ms
18,048 KB
testcase_23 AC 30 ms
18,688 KB
testcase_24 AC 32 ms
18,560 KB
testcase_25 AC 31 ms
18,432 KB
testcase_26 AC 30 ms
18,176 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;

namespace No367_1{
    public class Program{
        public static void Main(string[] args){
            var move = new[]{
                new[]{
                    new{X = -2, Y = -1},
                    new{X = -2, Y = +1},
                    new{X = -1, Y = -2},
                    new{X = -1, Y = +2},
                    new{X = +1, Y = -2},
                    new{X = +1, Y = +2},
                    new{X = +2, Y = -1},
                    new{X = +2, Y = +1}
                },
                new[]{
                    new{X = -1, Y = -1},
                    new{X = -1, Y = +1},
                    new{X = +1, Y = -1},
                    new{X = +1, Y = +1}
                }
            };

            var input = Console.ReadLine().Split(' ');
            var w = int.Parse(input[1]);
            var h = int.Parse(input[0]);

            var start = new Point(0, 0);
            var goal = new Point(0, 0);
            var map = new char[h][];
            for(var i = 0; i < h; i++){
                map[i] = Console.ReadLine().ToCharArray();
                int x;
                if((x = Array.IndexOf(map[i], 'S')) != -1){
                    start = new Point(x, i);
                } else if((x = Array.IndexOf(map[i], 'G')) != -1){
                    goal = new Point(x, i);
                }
            }

            var result = new int[w, h, 2];
            result[start.X, start.Y, 0] = 1;
            var que = new Queue<Stat>();
            que.Enqueue(new Stat(start.X, start.Y, 0));

            while(que.Count != 0){
                var now = que.Dequeue();
                foreach(var m in move[now.Type]){
                    if(0 <= now.X + m.X && now.X + m.X < w && 0 <= now.Y + m.Y && now.Y + m.Y < h){
                        var next = new Stat(
                            now.X + m.X,
                            now.Y + m.Y,
                            map[now.Y + m.Y][now.X + m.X] == 'R' ? 1 - now.Type : now.Type
                            );
                        if(result[next.X, next.Y, next.Type] == 0 || result[next.X, next.Y, next.Type] > result[now.X, now.Y, now.Type] + 1){
                            que.Enqueue(next);
                            result[next.X, next.Y, next.Type] = result[now.X, now.Y, now.Type] + 1;
                        }
                    }
                }
            }

            
            if((result[goal.X, goal.Y, 0] == result[goal.X, goal.Y, 1]) && result[goal.X, goal.Y, 0] == 0){
                Console.WriteLine(-1);
            } else{
                if(result[goal.X, goal.Y, 0] == 0) result[goal.X, goal.Y, 0] = int.MaxValue;
                if(result[goal.X, goal.Y, 1] == 0) result[goal.X, goal.Y, 1] = int.MaxValue;
                Console.WriteLine(Math.Min(result[goal.X, goal.Y, 0], result[goal.X, goal.Y, 1]) - 1);
            }
        }

        public class Stat{
            public Stat(int x, int y, int type){
                X = x;
                Y = y;
                Type = type;
            }

            public int X { get; }
            public int Y { get; }
            public int Type { get; }
        }

        public class Point{
            public Point(int x, int y){
                X = x;
                Y = y;
            }

            public int X { get; }
            public int Y { get; }
        }
    }
}
0