結果

問題 No.340 雪の足跡
ユーザー 14番14番
提出日時 2016-05-25 02:14:27
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 3,613 bytes
コンパイル時間 988 ms
コンパイル使用メモリ 116,036 KB
実行使用メモリ 218,848 KB
最終ジャッジ日時 2024-04-16 16:30:53
合計ジャッジ時間 5,732 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
34,516 KB
testcase_01 AC 31 ms
25,304 KB
testcase_02 AC 30 ms
27,216 KB
testcase_03 AC 30 ms
25,052 KB
testcase_04 AC 29 ms
27,348 KB
testcase_05 AC 30 ms
25,308 KB
testcase_06 AC 29 ms
25,184 KB
testcase_07 AC 30 ms
27,048 KB
testcase_08 AC 29 ms
23,352 KB
testcase_09 AC 31 ms
27,432 KB
testcase_10 AC 31 ms
25,312 KB
testcase_11 AC 39 ms
25,816 KB
testcase_12 AC 38 ms
31,160 KB
testcase_13 AC 42 ms
40,032 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 267 ms
218,848 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
        
        int width = inpt[0];
        int height = inpt[1];
        
        int otona = inpt[2];
        
        this.Road = new bool[width * height, width * height];
        for(int i=0; i<otona; i++) {
            int turnCount = int.Parse(Reader.ReadLine());
            inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
            
            if(inpt.Length > 1) {
                for(int j=1;j<inpt.Length; j++) {
                    int pos1 = Math.Min(inpt[j-1], inpt[j]);
                    int pos2 = Math.Max(inpt[j-1], inpt[j]);
                    if(pos1 % width == pos2 % width) {
                        // 同じ列
                        for(int k=pos1; k<pos2; k+=width) {
                            this.Road[k, k+width] = true;
                            this.Road[k+width, k] = true;
                        }
                    } else
                    {
                        // 多分同じ行
                        for(int k=pos1; k<pos2; k++) {
                            this.Road[k, k+1] = true;
                            this.Road[k+1, k] = true;
                        }
                    }
                }
            }
        }
        
        int[] map = new int[width * height];
        for(int i=0; i<width*height; i++) {
            map[i] = int.MaxValue;
        }
        map[0] = 0;
        Queue<int> taskQ = new Queue<int>();
        taskQ.Enqueue(0);
        while (taskQ.Count > 0)
        {
            int pos = taskQ.Dequeue();
            int row = pos / width;
            int col = pos % width;
            int nextVal = map[pos] + 1;
            
            int[][] nextPosList = new int[][] {new int[]{row + 1, col}, new int[] {row -1, col}, new int[]{row, col -1}, new int[]{row, col + 1}};
            foreach (int[] nextPos in nextPosList)
            {
                if(nextPos[1] < 0 || nextPos[1] >= width || nextPos[0] < 0 || nextPos[0] >= height) {
                    continue;
                }
                int nPos = nextPos[0] * width + nextPos[1];
                if(!this.Road[pos, nPos]) {
                    continue;
                }
                if(map[nPos] <= nextVal) {
                    continue;
                }
                map[nPos] = nextVal;
                if(nPos == width * height - 1) {
                    continue;
                }
                taskQ.Enqueue(nPos);
            }
        }
        int ans = map[width * height - 1];
        if(ans == int.MaxValue) {
            Console.WriteLine("Odekakedekinai..");
            return;
        }
        Console.WriteLine(ans);

    }
    
    private bool[,] Road;

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


3 3 2
2
0 1 4
2
4 7 8



";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0