結果

問題 No.179 塗り分け
ユーザー ふーらくたるふーらくたる
提出日時 2016-07-01 19:15:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,211 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 56,628 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 06:09:52
合計ジャッジ時間 1,887 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

const int kMAX_H = 60;
const int kMAX_W = 60;

string S[kMAX_H];
int color[kMAX_H][kMAX_W];
bool used[kMAX_H][kMAX_H];

int H, W, red, blue;

int dr[] = {1, 0, -1, 0},
    dc[] = {0, 1, 0, -1};

bool DFS(int row, int col, int c) {
    used[row][col] = true;
    color[row][col] = c;
    if (c == 1) red++;
    else blue--;

    for (int i = 0; i < 4; i++) {
        int nr = row + dr[i], nc = col + dc[i];
        if (0 <= nr && nr < H && 0 <= nc && nc < W && !used[nr][nc] && !DFS(nr, nc, -c)) {
            return false;
        }
    }

    return true;
}

void Solve() {
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '.') used[i][j] = true;
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (!used[i][j] && !DFS(i, j, 1)) {
                cout << "NO" << endl;
                return;
            }
        }
    }

    if ((red + blue) % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main() {
    cin >> H >> W;

    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }

    Solve();

    return 0;
}
0