結果

問題 No.13 囲みたい!
ユーザー 14番14番
提出日時 2016-03-31 01:18:15
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,216 bytes
コンパイル時間 997 ms
コンパイル使用メモリ 113,528 KB
実行使用メモリ 340,032 KB
最終ジャッジ日時 2024-04-10 06:39:20
合計ジャッジ時間 7,840 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
26,268 KB
testcase_01 AC 25 ms
24,240 KB
testcase_02 AC 27 ms
24,096 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

public class Program
{
    public void Proc(){
        Reader.IsDebug = false;
        int[] inpt = Reader.GetInt();
        this.Width = inpt[0];
        this.Height = inpt[1];
        this.map = new int[Height, Width];
        this.flag = new bool[Height, Width];
        for(int i=0; i<Height; i++) {
            inpt = Reader.GetInt();
            for(int j=0; j<inpt.Length; j++) {
                this.map[i,j] = inpt[j];
            }
        }
        
        for(int i=0; i<Height; i++) {
            for(int j=0; j<Width; j++) {
                if(!this.flag[i,j]) {
                    bool ret = this.GetAns(j,i,-1,-1,new List<String>());
                    if(ret) {
                        Console.WriteLine("possible");
                        return;
                    }
                }
            }
        }
        Console.WriteLine("impossible");
        
    }
    
    private int[,] map;
    private bool[,] flag;
    
    private bool GetAns(int posX, int posY, int prevX, int prevY, List<String> log) {
        string key = posX + "#" + posY;
        this.flag[posY, posX] = true;
        List<int[]> nextPosList = new List<int[]>();
        if(posX > 0) {
            nextPosList.Add(new int[]{posX - 1, posY });
        }
        if(posX < Width - 1) {
            nextPosList.Add(new int[]{posX + 1, posY });
        }
        if(posY > 0) {
            nextPosList.Add(new int[]{posX, posY - 1});
        }
        if(posY < Height - 1) {
            nextPosList.Add(new int[]{posX, posY + 1});
        }
        foreach (int[] pos in nextPosList)
        {
            if(pos[0] == prevX && pos[1] == prevY) {
                continue;
            }
            if(this.map[pos[1], pos[0]] != this.map[posY, posX]) {
                continue;
            }
            string nextKey = pos[0] + "#" + pos[1];
            if(log.Contains(nextKey)) {
                return true;
            }
            List<string> newLog = new List<string>();
            newLog.AddRange(log);
            newLog.Add(key);
            bool ret = this.GetAns(pos[0], pos[1], posX, posY, newLog);
            if(ret) {
                return true;
            }
        }
        return false;
    }
    private int Width;
    private int Height;
    


    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}

class Reader
{
    public static bool IsDebug = true;
    
    private static System.IO.StringReader sr;
    
    public static string ReadLine() {
        if(IsDebug) {
            if(sr == null) {
                sr = new System.IO.StringReader(initStr.Trim());
            }
            return sr.ReadLine();
        } else {
            return Console.ReadLine();
        }
    }
    
    public static int[] GetInt(char delimiter = ' ') {
        string[] inpt = ReadLine().Split(delimiter);
        int[] ret = new int[inpt.Length];
        for(int i=0; i<inpt.Length; i++) {
            ret[i] = int.Parse(inpt[i]);
        }
        return ret;
    }
    
    private static string initStr = @"



5 4
5 5 5 3 5
5 3 1 5 1
5 2 2 5 8
5 5 5 5 9


";
}

0