結果

問題 No.179 塗り分け
ユーザー nuwasoginuwasogi
提出日時 2015-11-23 16:29:03
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 195 ms / 3,000 ms
コード長 4,729 bytes
コンパイル時間 2,895 ms
コンパイル使用メモリ 108,012 KB
実行使用メモリ 47,436 KB
最終ジャッジ日時 2023-09-30 20:45:07
合計ジャッジ時間 8,569 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
21,804 KB
testcase_01 AC 61 ms
21,856 KB
testcase_02 AC 60 ms
21,896 KB
testcase_03 AC 62 ms
23,852 KB
testcase_04 AC 61 ms
21,844 KB
testcase_05 AC 69 ms
25,956 KB
testcase_06 AC 62 ms
23,836 KB
testcase_07 AC 59 ms
21,864 KB
testcase_08 AC 176 ms
45,924 KB
testcase_09 AC 174 ms
43,724 KB
testcase_10 AC 61 ms
22,060 KB
testcase_11 AC 63 ms
23,964 KB
testcase_12 AC 164 ms
47,436 KB
testcase_13 AC 61 ms
22,036 KB
testcase_14 AC 61 ms
23,932 KB
testcase_15 AC 61 ms
19,976 KB
testcase_16 AC 60 ms
21,872 KB
testcase_17 AC 58 ms
21,740 KB
testcase_18 AC 64 ms
22,744 KB
testcase_19 AC 64 ms
22,644 KB
testcase_20 AC 169 ms
44,492 KB
testcase_21 AC 183 ms
45,728 KB
testcase_22 AC 195 ms
43,688 KB
testcase_23 AC 62 ms
21,812 KB
testcase_24 AC 178 ms
45,788 KB
testcase_25 AC 64 ms
21,884 KB
testcase_26 AC 79 ms
29,792 KB
testcase_27 AC 178 ms
45,804 KB
testcase_28 AC 67 ms
23,468 KB
testcase_29 AC 177 ms
45,772 KB
testcase_30 AC 109 ms
43,572 KB
testcase_31 AC 177 ms
43,760 KB
testcase_32 AC 93 ms
37,272 KB
testcase_33 AC 176 ms
41,680 KB
testcase_34 AC 83 ms
32,308 KB
testcase_35 AC 177 ms
45,616 KB
testcase_36 AC 61 ms
21,940 KB
testcase_37 AC 61 ms
21,812 KB
testcase_38 AC 61 ms
21,884 KB
testcase_39 AC 60 ms
21,824 KB
testcase_40 AC 60 ms
21,896 KB
testcase_41 AC 60 ms
23,820 KB
testcase_42 AC 60 ms
21,996 KB
testcase_43 AC 62 ms
19,860 KB
testcase_44 AC 69 ms
26,056 KB
testcase_45 AC 61 ms
21,888 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;
using System.Linq;

namespace Nuriwake_CS
{
    class Program
    {
        static void Main(string[] args)
        {
            Solver mysol = new Solver();
            mysol.Solve();
        }
    }

    class Solver
    {
        public void Solve()
        {
            bool ans = B.CanNuriwake();
            Console.WriteLine(ans ? "YES" : "NO");
        }

        int H, W;
        Board B;

        public Solver()
        {
            var hw = ria();
            H = hw[0];
            W = hw[1];
            string[] s = new string[H];

            for (int i = 0; i < s.Length; i++)
            {
                s[i] = rs();
            }
            B = new Board(H, W, s);

        }

        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(); }
    }

    class Board
    {
        public enum color { Black, White, Red, Blue }

        int H, W;
        color[,] BaseBoard;
        int BlackNum;

        public Board(int h, int w, string[] s)
        {
            H = h;
            W = w;
            BlackNum = 0;
            BaseBoard = new color[H, W];
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    if (s[i][j] == '#')
                    {
                        BaseBoard[i, j] = color.Black;
                        BlackNum++;
                    }
                    else
                    {
                         BaseBoard[i,j] = color.White;
                    }
                }
            }
        }

        public bool CanNuriwake()
        {
            if(BlackNum == 0)
            {
                return false;
            }

            color[,] curBoard = new color[H, W];
            var shifts = Coordinate.MakeParallelShifts(H, W);
            foreach (Coordinate c in shifts)
            {
                curBoard = BaseCopy();
                bool ok = true;
                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++)
                    {
                        if (curBoard[i, j] == color.Black)
                        {
                            curBoard[i, j] = color.Red;
                            try
                            {
                                if (curBoard[i + c.X, j + c.Y] == color.Black)
                                {
                                    curBoard[i + c.X, j + c.Y] = color.Blue;
                                }
                                else
                                {
                                    ok = false;
                                    break;
                                }
                            }
                            catch (Exception e)
                            {
                                ok = false;
                                break;
                            }
                        }
                    }
                    if (ok == false) break;
                }
                if (ok) return ok;
            }
            return false;
        }
        color[,] BaseCopy()
        {
            color[,] ret = new color[H, W];
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    ret[i, j] = BaseBoard[i, j];
                }
            }
            return ret;
        }
    }

    struct Coordinate
    {
        public int X, Y;
        Coordinate(int x, int y)
        {
            X = x;
            Y = y;
        }
        public static Queue<Coordinate> MakeParallelShifts(int H, int W)
        {
            Queue<Coordinate> q = new Queue<Coordinate>();
            for (int i = 0, j = 0; j < W; j++)
            {
                q.Enqueue(new Coordinate(i, j));
            }
            for (int i = 1; i < H; i++)
            {
                for (int j = -W + 1; j < W; j++)
                {
                    q.Enqueue(new Coordinate(i, j));
                }
            }
            q.Dequeue();
            return q;
        }
    }
}
0