結果

問題 No.179 塗り分け
ユーザー h_noson
提出日時 2016-02-18 12:21:12
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 84 ms / 3,000 ms
コード長 1,149 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 66,532 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 14:33:54
合計ジャッジ時間 2,894 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (int i = e-1; i >= s; i--)
#define rrep(i,n) RREP(i,0,n)
#define REP(i,s,e) for (int i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)

bool search(vector<string>& s) {
    int h = s.size();
    int w = s[0].size();
    int found;
    bool ret = false;
    rep (di,h) rep (dj,w) {
        found = -1;
        vector<string> b = s;
        if (di == 0 && dj == 0)
            continue;
        rep (i,h) rep (j,w) {
            if (b[i][j] == '#') {
                if (i+di < h && j+dj < w && b[i+di][j+dj] == '#') {
                    b[i+di][j+dj] = '.';
                    found *= found;
                }
                else
                    found = 0;
            }
        }
        ret |= found == 1;
    }
    return ret;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s;
    s.resize(h);
    rep (i,h) cin >> s[i];

    bool ans = search(s);
    rep (i,h) reverse(s[i].begin(),s[i].end());
    ans |= search(s);
    if (ans)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}
0