結果

問題 No.179 塗り分け
ユーザー 14番
提出日時 2016-03-29 23:32:18
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,186 ms / 3,000 ms
コード長 3,079 bytes
コンパイル時間 1,199 ms
コンパイル使用メモリ 114,008 KB
実行使用メモリ 49,292 KB
最終ジャッジ日時 2024-07-23 14:36:12
合計ジャッジ時間 13,430 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
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();
        int wLen = inpt[1];
        int hLen = inpt[0];
        this.Map = new BlockState[hLen, wLen];
        for(int i=0; i<hLen; i++) {
            string str = Reader.ReadLine();
            for(int j=0;j<str.Length; j++) {
                if(str[j] == '#') {
                    this.Map[i,j] = BlockState.black;
                } else
                {
                    this.Map[i,j] = BlockState.white;
                }
            }
        }
        for(int i=0; i<hLen; i++) {
            for(int j=(wLen -1)*-1; j<wLen; j++) {
                if(CanPaint(j,i)) {
                    Console.WriteLine("YES");
                    return;
                }
            }
        }
        Console.WriteLine("NO");
    }
    
    private bool CanPaint(int x, int y) {
        if(x == 0 && y == 0) {
            return false;
        }
        bool isPainted = false;
        BlockState[,] map = CopyMap();
        for(int i=0; i<map.GetLength(0); i++) {
            for(int j=0; j<map.GetLength(1); j++) {
                if(map[i,j]==BlockState.black) {
                    int px = j+x;
                    int py = i+y;
                    if(px >= 0 && px < map.GetLength(1) && py>=0 && py < map.GetLength(0) && map[py, px] == BlockState.black) {
                        map[i,j] = BlockState.blue;
                        map[py, px] = BlockState.read;
                        isPainted = true;
                    } else
                    {
                         return false;
                    }
                }
            }
        }
        return isPainted;
    }
    private BlockState[,] Map;
    
    private BlockState[,] CopyMap() {
        BlockState[,] newMap = new BlockState[this.Map.GetLength(0), this.Map.GetLength(1)];
        for(int i=0; i<this.Map.GetLength(0); i++) {
            for(int j=0; j<this.Map.GetLength(1); j++) {
                newMap[i,j] = Map[i,j];
            }
        }
        return newMap;
    }
    
    enum BlockState {
        white,
        black,
        read,
        blue
    }
    
    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 = @"





    ";
}

0