結果

問題 No.179 塗り分け
ユーザー aaaaaaiu
提出日時 2019-08-08 02:46:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 3,000 ms
コード長 1,050 bytes
コンパイル時間 1,803 ms
コンパイル使用メモリ 194,712 KB
最終ジャッジ日時 2025-01-07 11:00:26
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int h,w;
    cin>>h>>w;
    string s[h];
    for (int i=0;i<h;i++) cin>>s[i];
    int b=0;
    for (auto str:s) for (auto c:str) b+=c=='#';
    if (b==0||b&1) {
        puts("NO");
        return 0;
    }
    for (int dy=0;dy<h;dy++) {
        for (int dx=-w+1;dx<w;dx++) {
            if (dy==0&&dx==0) continue;
            bool used[h][w]{};
            bool ok=true;
            for (int y=0;y<h;y++) {
                for (int x=0;x<w;x++) {
                    if (s[y][x]!='#'||used[y][x]) continue;
                    int ny=y+dy, nx=x+dx;
                    if (h<=ny||nx<0||w<=nx||s[ny][nx]!='#'||used[ny][nx]) {
                        ok=false;
                        break;
                    }
                    used[y][x]=used[ny][nx]=true;
                }
                if (!ok) break;
            }
            if (ok) {
                puts("YES");
                return 0;
            }
        }
    }
    puts("NO");
    return 0;
}
0