結果

問題 No.179 塗り分け
ユーザー @abcde@abcde
提出日時 2019-06-01 00:34:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,168 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 169,828 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 22:39:14
合計ジャッジ時間 5,932 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 WA -
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 18 ms
4,348 KB
testcase_25 AC 18 ms
4,348 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 RE -
testcase_44 AC 8 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// ロジック修正.
#include <bits/stdc++.h>
using namespace std;

int main() {
    
    // 1. 入力情報取得.
    int H, W;
    cin >> H >> W;
    char c[H][W];
    for(int i = 0; i < H; i++){
        string s;
        cin >> s;
        for(int j = 0; j < W; j++) c[i][j] = s[j];
    }

    // 2. '#' を カウント.
    int sharp = 0;
    for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) if(c[i][j] == '#') sharp++;
    
    // 2-1. '#' の 個数が, 奇数の場合.
    if(sharp % 2 != 0){
        cout << "NO" << endl;
        return 0;
    }
    
    // 2-2. '#' の 個数が, 0個の場合.
    if(sharp == 0){
        cout << "NO" << endl;
        return 0;
    }
    
    // 2-3. '#' の 個数が, 偶数の場合.
    // (仮称)青の領域で, 1点固定して, ベクトルを一つ固定し, 青の領域を全探索した結果, 
    // すべて, ベクトル方向に, '#' であれば, 塗り分けが存在すると判定.
    // ベクトルを, 1つ固定.
    string ans = "NO";
    for(int vh = 0; vh < H; vh++){
        for(int vw = 0; vw < W; vw++){
            // ベクトル(0, 0) は, Skip.
            if(vh == 0 && vw == 0) continue;
            // 訪問したら, 1, 2 を セット.
            int memo[H][W] = {};
            for(int h = 0; h < H; h++){
                for(int w = 0; w < W; w++){
                    if(c[h][w] == '#' && memo[h][w] == 0 && c[h + vh][w + vw] == '#'){
                        memo[h][w] = 1;
                        memo[h + vh][w + vw] = 2;
                    }
                }
            }
            int one = 0, two = 0;
            for(int h = 0; h < H; h++){
                for(int w = 0; w < W; w++){
                    if(memo[h][w] == 1) one++;
                    if(memo[h][w] == 2) two++;
                }
            }
            // if(vh == 6 && vw == 5){
            //     for(int h = 0; h < H; h++){
            //         for(int w = 0; w < W; w++){
            //             cout << memo[h][w] << " ";
            //         }
            //         cout << endl;
            //     }
            // }
            // 塗り分け の 存在チェック.
            if(one == sharp / 2 && two == sharp / 2){
                ans = "YES";
                break;
            }
        }
    }

    // 3. 出力.
    // ex.
    // [入力例]
    // 11 17
    // .#.#.#.#.........
    // #.#.#.#.#..#.....
    // .#.#.#.#.##......
    // ..#.#.#..##......
    // ...#.#...........
    // .................
    // ......#.#.#.#....
    // .....#.#.#.#.#..#
    // ......#.#.#.#.##.
    // .......#.#.#..##.
    // ........#.#......
    // 
    // 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 
    // 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 
    // 0 1 0 1 0 1 0 1 0 1 1 0 0 0 0 0 0 
    // 0 0 1 0 1 0 1 0 0 1 1 0 0 0 0 0 0 
    // 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 
    // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    // 0 0 0 0 0 0 2 0 2 0 2 0 2 0 0 0 0 
    // 0 0 0 0 0 2 0 2 0 2 0 2 0 2 0 0 2 
    // 0 0 0 0 0 0 2 0 2 0 2 0 2 0 2 2 0 
    // 0 0 0 0 0 0 0 2 0 2 0 2 0 0 2 2 0 
    // 0 0 0 0 0 0 0 0 2 0 2 0 0 0 0 0 0 
    // YES
    cout << ans << endl;
    return 0;
    
}
0