結果

問題 No.179 塗り分け
ユーザー tk3628800tk3628800
提出日時 2021-03-05 17:10:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 3,000 ms
コード長 1,624 bytes
コンパイル時間 1,959 ms
コンパイル使用メモリ 176,428 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 04:41:01
合計ジャッジ時間 4,139 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 7 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 48 ms
5,376 KB
testcase_09 AC 47 ms
5,376 KB
testcase_10 AC 21 ms
5,376 KB
testcase_11 AC 18 ms
5,376 KB
testcase_12 AC 36 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 18 ms
5,376 KB
testcase_19 AC 17 ms
5,376 KB
testcase_20 AC 31 ms
5,376 KB
testcase_21 AC 43 ms
5,376 KB
testcase_22 AC 46 ms
5,376 KB
testcase_23 AC 20 ms
5,376 KB
testcase_24 AC 43 ms
5,376 KB
testcase_25 AC 22 ms
5,376 KB
testcase_26 AC 20 ms
5,376 KB
testcase_27 AC 37 ms
5,376 KB
testcase_28 AC 19 ms
5,376 KB
testcase_29 AC 36 ms
5,376 KB
testcase_30 AC 26 ms
5,376 KB
testcase_31 AC 35 ms
5,376 KB
testcase_32 AC 25 ms
5,376 KB
testcase_33 AC 36 ms
5,376 KB
testcase_34 AC 22 ms
5,376 KB
testcase_35 AC 36 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 3 ms
5,376 KB
testcase_44 AC 6 ms
5,376 KB
testcase_45 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<vector<char>> a;
int h,w;
bool Isvalid(int x,int y,vector<vector<int>> &Isseen){//ある平行移動がvaildか
    bool flag = 1;
    rep(i,h)rep(j,w){
        if(a[i][j]=='.') continue;//すべての黒ますについて
        if(Isseen[i][j]) continue;//もしすでに見ていたらcontinue
        Isseen[i][j] = 1; //訪問済みにする
        int nowx = x+i,nowy = y+j;//平行移動先
        if(nowx<0||h<=nowx||nowy<0||w<=nowy){//はみ出したらだめ
            flag = 0;
            break;
        } 
        if(a[nowx][nowy]=='.'){//移動先が白でもダメ
            flag = 0;
            break;
        }
        if(Isseen[nowx][nowy]){
            flag = 0;//移動先が訪問済みでもダメ
            break;
        }
        Isseen[nowx][nowy] = 2;
    }
    return flag;
}
int main(void){
    cin >> h >> w;
    a.resize(h,vector<char> (w));
    int flag = 0;
    rep(i,h)rep(j,w){
        cin >> a[i][j];
        if(a[i][j]=='#') flag = 1;
    } 
    if(!flag){
        cout << "NO" << endl;
        return 0;
    }
    for(int i=-h+1;i<=h-1;i++){
        for(int j=-w+1;j<=w-1;j++){
        if(i==0&&j==0) continue;
        vector<vector<int>> Isseen(h,vector<int> (w,0));
        if(Isvalid(i,j,Isseen)){
            //cout << i << j << endl;
            cout << "YES" << endl;
            //rep(i,h){
            //    rep(j,w) cout << Isseen[i][j];
            //    cout << endl;
            //}
            return 0;
        }
        }
    }
    cout << "NO" << endl;
}
0