結果

問題 No.179 塗り分け
ユーザー mayoko_
提出日時 2015-04-06 00:10:18
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,213 bytes
コンパイル時間 1,670 ms
コンパイル使用メモリ 159,076 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-02 13:23:20
合計ジャッジ時間 2,687 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 38 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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;
                continue;
            } 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;
    for (int i = 0; i < H; i++) {
        cin >> s[i];
    }
    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