結果

問題 No.179 塗り分け
ユーザー t98slider
提出日時 2022-06-22 10:29:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 142 ms / 3,000 ms
コード長 2,178 bytes
コンパイル時間 1,823 ms
コンパイル使用メモリ 176,528 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 13:57:40
合計ジャッジ時間 4,167 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int H, W, cnt = 0;
    cin >> H >> W;
    vector<string> A(H);
    for(auto &&s:A){
        cin >> s;
        cnt += count(s.begin(), s.end(), '#');
    }
    if(cnt == 0){
        cout << "NO" << endl;
        return 0;
    }
    for(int my = 0; my < H; my++){
        for(int mx = 0; mx < W; mx++){
            if(my == 0 && mx == 0)continue;
            bool flag = true;
            vector<vector<bool>> used(H, vector<bool>(W));
            for(int y = 0; y < H; y++){
                for(int x = 0; x < W; x++){
                    if(used[y][x])continue;
                    if(A[y][x] != '#')continue;
                    if(y + my >= H || x + mx >= W){
                        flag = false;
                        continue;
                    }
                    used[y][x] = true;
                    if(A[y + my][x + mx] == '#'){
                        used[y + my][x + mx] = true;
                    }else{
                        flag = false;
                    }
                }
            }
            if(flag){
                cout << "YES" << '\n';
                return 0;
            }
        }
    }
    for(auto &&s:A)reverse(s.begin(), s.end());
    for(int my = 0; my < H; my++){
        for(int mx = 0; mx < W; mx++){
            if(my == 0 && mx == 0)continue;
            bool flag = true;
            vector<vector<bool>> used(H, vector<bool>(W));
            for(int y = 0; y < H; y++){
                for(int x = 0; x < W; x++){
                    if(used[y][x])continue;
                    if(A[y][x] != '#')continue;
                    if(y + my >= H || x + mx >= W){
                        flag = false;
                        continue;
                    }
                    used[y][x] = true;
                    if(A[y + my][x + mx] == '#'){
                        used[y + my][x + mx] = true;
                    }else{
                        flag = false;
                    }
                }
            }
            if(flag){
                cout << "YES" << '\n';
                return 0;
            }
        }
    }
    cout << "NO" << '\n';
}
0