結果

問題 No.179 塗り分け
ユーザー bayashiko_rbayashiko_r
提出日時 2019-01-03 02:32:52
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 186 ms / 3,000 ms
コード長 4,309 bytes
コンパイル時間 3,057 ms
コンパイル使用メモリ 103,096 KB
実行使用メモリ 22,792 KB
最終ジャッジ日時 2023-09-30 21:06:58
合計ジャッジ時間 8,481 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
20,640 KB
testcase_01 AC 55 ms
20,556 KB
testcase_02 AC 55 ms
22,656 KB
testcase_03 AC 55 ms
20,608 KB
testcase_04 AC 55 ms
20,744 KB
testcase_05 AC 55 ms
20,660 KB
testcase_06 AC 56 ms
22,764 KB
testcase_07 AC 57 ms
20,776 KB
testcase_08 AC 142 ms
22,692 KB
testcase_09 AC 143 ms
22,752 KB
testcase_10 AC 55 ms
20,712 KB
testcase_11 AC 56 ms
20,616 KB
testcase_12 AC 152 ms
22,744 KB
testcase_13 AC 56 ms
22,676 KB
testcase_14 AC 55 ms
20,588 KB
testcase_15 AC 56 ms
20,692 KB
testcase_16 AC 55 ms
20,684 KB
testcase_17 AC 55 ms
22,656 KB
testcase_18 AC 59 ms
20,776 KB
testcase_19 AC 60 ms
20,708 KB
testcase_20 AC 56 ms
22,772 KB
testcase_21 AC 55 ms
20,684 KB
testcase_22 AC 144 ms
20,692 KB
testcase_23 AC 58 ms
18,632 KB
testcase_24 AC 144 ms
20,624 KB
testcase_25 AC 100 ms
20,616 KB
testcase_26 AC 102 ms
18,644 KB
testcase_27 AC 163 ms
20,612 KB
testcase_28 AC 124 ms
20,672 KB
testcase_29 AC 176 ms
20,728 KB
testcase_30 AC 94 ms
22,756 KB
testcase_31 AC 186 ms
22,668 KB
testcase_32 AC 115 ms
20,752 KB
testcase_33 AC 176 ms
22,688 KB
testcase_34 AC 62 ms
20,740 KB
testcase_35 AC 183 ms
20,676 KB
testcase_36 AC 55 ms
20,744 KB
testcase_37 AC 55 ms
22,656 KB
testcase_38 AC 55 ms
20,704 KB
testcase_39 AC 56 ms
22,788 KB
testcase_40 AC 55 ms
20,616 KB
testcase_41 AC 55 ms
22,644 KB
testcase_42 AC 55 ms
18,560 KB
testcase_43 AC 57 ms
22,792 KB
testcase_44 AC 68 ms
20,604 KB
testcase_45 AC 55 ms
20,612 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

class Program {
    static void Main(string[] args) {
        #region

        //入力
        string a = Console.ReadLine();
        int H = int.Parse(a.Split(' ')[0]);
        int W = int.Parse(a.Split(' ')[1]);

        string[] row = new string[H];

        for (int i = 0; i < H; i++) {
            row[i] = Console.ReadLine();
        }

        //#を数える用の変数
        int num_sharp = 0;

        //全マスを二行に列の配列として扱う
        char[,] field = new char[H, W];
        //置き換え用
        char[,] kari = new char[H, W];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                field[i, j] = row[i][j];
                kari[i, j] = field[i, j];
                if (row[i][j] == '#') {
                    num_sharp++;
                }
            }
        }

        //Console.WriteLine(num_sharp);

        #endregion //ここは大丈夫

        //回答用フラグ
        bool flg = false;

        if (num_sharp % 2 == 1 || num_sharp == 0) {
            //#の個数が奇数の時(もしくは0の時)は、絶対にペアは作れない
            flg = false;
        } else {


            //計算実行
            for (int i = 0; i < W; i++) {
                for (int j = -H + 1; j < H; j++) {
                    //Console.WriteLine("●(i, j) = (" + i + "," + j + ")");

                    //毎回リセットする
                    int counter = 0;
                    for (int an = 0; an < H; an++) {
                        for (int b = 0; b < W; b++) {
                            kari[an, b] = field[an, b];
                        }
                    }

                    //平行移動しないものは飛ばす
                    if (i == 0 && j == 0) {
                        continue;
                    }
                  
                    //kariのR-Area全てのcharについて、調査する
                    if (j >= 0) {
                        for (int tate = j; tate < H; tate++) {
                            
                            for (int yoko = 0; yoko < W - i; yoko++) {
                                //Console.WriteLine("(tate, yoko) = (" + tate + "," + yoko + ")");
                                if (kari[tate, yoko] == '#') {
                                    //Console.WriteLine("a");
                                    if (kari[tate, yoko] == kari[tate - j, yoko + i]) {
                                        counter++;
                                        //Console.WriteLine("b");
                                        kari[tate, yoko] = '.';
                                        kari[tate - j, yoko + i] = '.';
                                    }
                                    //Console.WriteLine(counter);
                                }
                            }
                        }
                    } else if (j < 0) {
                        for (int tate = 0; tate < H + j; tate++) {
                            for (int yoko = 0; yoko < W - i; yoko++) {
                                //Console.WriteLine("(tate, yoko) = (" + tate + "," + yoko + ")");
                                if (kari[tate, yoko] == '#') {
                                    //Console.WriteLine("a");
                                    if (kari[tate, yoko] == kari[tate - j, yoko + i]) {
                                        counter++;
                                        //Console.WriteLine("b");
                                        kari[tate, yoko] = '.';
                                        kari[tate - j, yoko + i] = '.';
                                    }
                                    //Console.WriteLine(counter);
                                }
                            }
                        }
                    }
                    //Console.WriteLine(counter);

                    //flgの判定
                    if (counter == num_sharp / 2) {
                        flg = true;
                        goto LABEL;
                    }
                }
            }
        }

        LABEL:

        //出力
        if (!flg) {
            Console.WriteLine("NO");
        } else {
            Console.WriteLine("YES");
        }
    }
}
0