結果

問題 No.179 塗り分け
ユーザー zeronosu77108
提出日時 2021-01-16 17:27:02
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 89 ms / 3,000 ms
コード長 1,804 bytes
コンパイル時間 2,422 ms
コンパイル使用メモリ 144,956 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-27 21:37:19
合計ジャッジ時間 4,708 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

//
// Created by zeronosu77108 on Jan 15, 2021.
//
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>
#include <complex>
#include <optional>
#include <climits>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<(v)<<endl;}

int main() {
    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    for (int i=0; i<h; i++) cin >> s[i];

    {
        int cnt = 0;
        for (int i=0; i<h; i++) cnt += count(s[i].begin(), s[i].end(), '#');
        if (cnt<2) {
            cout << "NO" << endl;
            return 0;
        }
    }

    for (int dy=-h; dy<h; dy++) {
        for (int dx=-w; dx<w; dx++) {
            if (dy==0 && dx==0) continue;
            vector used(h, vector(w, false));

            bool f = true;
            for (int i=0; i<h; i++) {
                for (int j=0; j<w; j++) {
                    if (s[i][j] == '.') continue;
                    if (used[i][j]) continue;
                    used[i][j] = true;

                    if (i+dy<0 || h<=i+dy || j+dx<0 || w<=j+dx) {f=false; break; }
                    if (s[i+dy][j+dx] == '.') {f=false; break;}
                    used[i+dy][j+dx] = true;
                }
                if (!f) break;
            }

            if (f) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

     cout << "NO" << endl;
}
0