結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 13 ms
4,348 KB
testcase_09 WA -
testcase_10 AC 14 ms
4,348 KB
testcase_11 AC 11 ms
4,348 KB
testcase_12 AC 14 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
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 AC 14 ms
4,348 KB
testcase_19 AC 14 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 14 ms
4,348 KB
testcase_23 AC 17 ms
4,348 KB
testcase_24 AC 15 ms
4,348 KB
testcase_25 AC 15 ms
4,348 KB
testcase_26 WA -
testcase_27 AC 26 ms
4,348 KB
testcase_28 WA -
testcase_29 AC 31 ms
4,348 KB
testcase_30 WA -
testcase_31 AC 32 ms
4,348 KB
testcase_32 AC 30 ms
4,348 KB
testcase_33 AC 30 ms
4,348 KB
testcase_34 WA -
testcase_35 AC 32 ms
4,348 KB
testcase_36 AC 1 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 AC 2 ms
4,348 KB
testcase_44 AC 5 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++){
                    // ※ロジック修正.
                    int uh = h + vh;
                    int uw = w + vw;
                    if(uh < H && uw < W && c[h][w] == '#' && memo[h][w] == 0 && c[uh][uw] == '#'){
                        memo[h][w] = 1;
                        memo[uh][uw] = 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