結果

問題 No.179 塗り分け
ユーザー mayoko_
提出日時 2015-04-06 08:46:58
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 10 ms / 3,000 ms
コード長 1,357 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 159,380 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-23 14:27:46
合計ジャッジ時間 2,712 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)

using namespace std;
typedef long long ll;

const int MAXH = 64;
string s[MAXH];
bool used[MAXH][MAXH];
int H, W;

bool ok(int dx, int dy) {
    memset(used, 0, sizeof(used));
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (s[y][x] == '.' || used[y][x]) continue;
            used[y][x] = true;
            int ny = y+dy, nx = x+dx;
            if (ny < 0 || ny >= H || nx < 0 || nx >= W) return false;
            if (s[ny][nx] == '#' && !used[ny][nx]) {
                used[ny][nx] = true;
            } else {
                return false;
            }
        }
    }
    for (int y = 0; y < H; y++) for (int x = 0; x < W; x++) {
        if (s[y][x] == '#' && !used[y][x]) return false;
    }
    return true;
}

int main() {
    cin >> H >> W;
    int cnt = 0;
    for (int i = 0; i < H; i++) {
        cin >> s[i];
        for (int j = 0; j < W; j++) if (s[i][j] == '#') cnt++;
    }
    if (cnt % 2 == 1 || cnt == 0) {
        cout << "NO" << endl;
        return 0;
    }
    for (int dx = -W; dx <= W; dx++) {
        for (int dy = -H; dy <= H; dy++) {
            if (ok(dx, dy)) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}
0