結果
| 問題 | 
                            No.179 塗り分け
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-01-09 12:04:34 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 89 ms / 3,000 ms | 
| コード長 | 1,043 bytes | 
| コンパイル時間 | 1,697 ms | 
| コンパイル使用メモリ | 193,760 KB | 
| 最終ジャッジ日時 | 2025-02-10 01:22:08 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 6 | 
| other | AC * 40 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int h,w,cnt;
char s[60][60],t[60][60];
int main(){
    cin>>h>>w;
    for(int i=1;i<=h;++i)
        for(int j=1;j<=w;++j){
            cin>>s[i][j];
            if(s[i][j]=='#')
                ++cnt;
        }
    if(cnt>=2){
        for(int dx=-h+1;dx<=h-1;++dx)
            for(int dy=-w+1;dy<=w-1;++dy){
                if(dx==0&&dy==0) continue;
                memcpy(t,s,sizeof(s));
                int tot=cnt;
                for(int x=1;x<=h;++x)
                    for(int y=1;y<=w;++y){
                        int xx=x+dx,yy=y+dy;
                        if(xx<1||xx>h||yy<1||y>w) continue;
                        if(t[x][y]=='#'&&t[xx][yy]=='#'){
                            t[x][y]='R';
                            t[xx][yy]='B';
                            tot-=2;
                        }
                    }
                if(tot==0){
                    cout<<"YES"<<endl;
                    return 0;
                }
            }
    }
    cout<<"NO";
    return 0;
}