結果

問題 No.179 塗り分け
ユーザー fiord
提出日時 2015-07-08 22:14:38
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 14 ms / 3,000 ms
コード長 888 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 162,176 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 14:31:24
合計ジャッジ時間 2,719 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int h,w;
bool check(int mx,int my,vector<string> s){
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(s[i][j]=='#'){
				if(!(0<=i+my&&i+my<h&&0<=j+mx&&j+mx<w))	continue;
				s[i][j]='R';
				if(s[i+my][j+mx]=='#')	s[i+my][j+mx]='B';
				else 	return false;
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(s[i][j]=='#')	return false;
		}
	}
	return true;
}

void end(){
	cout<<"YES"<<endl;
	exit(0);
}

int main(){
	cin>>h>>w;
	vector<string> s(h);
	for(int i=0;i<h;i++)	cin>>s[i];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(s[i][j]=='#'){
				for(int toj=j+1;toj<w;toj++){
					if(check(toj-j,0,s))	end();
				}
				for(int toi=i+1;toi<h;toi++){
					for(int toj=0;toj<w;toj++){
						if(check(toj-j,toi-i,s))	end();
					}
				}
				cout<<"NO"<<endl;
				return 0;
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}
0