結果

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

ソースコード

diff #

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<25;
typedef pair<int,int> P;
typedef long long ll;
typedef unsigned long long ull;

int h, w;
string s[200];
string res[2] = {"NO", "YES"};

bool check(int dx, int dy){
	int g[60][60];
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			g[i][j] = s[i][j]=='#';
	for(int i = 0; i < h; i++){
		for(int j_ = 0; j_ < w; j_++){
			int j = dy<0?w-j_-1:j_;
			if(g[i][j]){
				int i2 = i+dx, j2 = j+dy;
				if(i2>=h || j2>=w || i2<0 || j2<0 || !g[i2][j2]) return false;
				g[i2][j2] = 0;
			}
		}
	}
	return true;
}

int main(){
	cin>>h>>w;
	for(int i = 0; i < h; i++) cin>>s[i];
	bool ok = false, ng = true;
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			if(s[i][j]=='#') ng = false;
	for(int i = 0; i < h; i++){
		for(int j = -w+1; j < w; j++){
			if(i==0 && j==0) continue;
			if(check(i, j)){
				ok = true;
				i = h;
				break;
			}
		}
	}
	cout<<res[ok && !ng]<<endl;
	return 0;
}
0