結果

問題 No.179 塗り分け
ユーザー sugarrr
提出日時 2018-03-03 15:42:59
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 6 ms / 3,000 ms
コード長 1,444 bytes
コンパイル時間 786 ms
コンパイル使用メモリ 79,476 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 14:46:18
合計ジャッジ時間 1,851 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/
#define rep(i,l,r) for(int i=l;i<=r;i++)
const double EPS=1E-8;

////////////////////////////////////////
int h,w;
char p[55][55+1];
bool flag=false;
void solve(int x,int y){
    char m[h][w+1];
    rep(i,0,h-1)rep(j,0,w-1)m[i][j]=p[i][j];
    rep(i,0,h-1)rep(j,0,w-1){
        if(m[i][j]=='#'){
            m[i][j]='.';
            if(i+x>=h||j+y>=w||i+x<0||j+y<0)return;
            if(m[i+x][j+y]=='.')return;
            m[i+x][j+y]='.';
        }
    }
    bool flg=true;
    rep(i,0,h-1)rep(j,0,w-1)if(m[i][j]!='.')flg=false;
    if(flg){
        cout<<"YES"; /* printf(" %d %d ",x,y);*/
    flag=true;
    }
}



int main(){
    cin>>h>>w;
    rep(i,0,h-1)cin>>p[i];
    bool a=false;
    rep(i,0,h-1){
        rep(j,0,w-1){
            if(p[i][j]=='#')a=true;
        }
    }
    if(!a){
        cout<<"NO";return 0;
    }
    rep(i,0,h-1){
        rep(j,-w+1,w-1){
            if(!flag)solve(i,j);
        }
    }
    if(!flag)cout<<"NO";
    
    return 0;
}
0