結果

問題 No.179 塗り分け
ユーザー Ilag
提出日時 2020-06-24 21:59:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,327 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 170,336 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-03 20:21:32
合計ジャッジ時間 2,560 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 34 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int h, w;
    cin >> h >> w;
    string s[h];
    int sum = 0;
    for (int i = 0; i < h; i++) {
        cin >> s[i];
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') sum++;
        }
    }
    for (int dy = 0; dy < h; dy++) {
        for (int dx = 0; dx < w; dx++) {
            if (dy == 0 && dx == 0) continue;
            int color[h][w] = {};
            int cnt = 0;
            bool flag = true;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (s[i][j] != '#') continue;
                    if (color[i][j] > 0) continue;
                    int ny = i + dy, nx = j + dx;
                    if (0 <= ny && ny < h && 0 <= nx && nx < w && color[ny][nx] == 0) {
                        color[i][j] = 1;
                        color[ny][nx] = 2;
                        cnt += 2;
                    } else {
                        flag = false;
                        break;
                    }
                }
                if (!flag) break;
            }
            if (sum == cnt && flag) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}
0