結果

問題 No.179 塗り分け
ユーザー chocorusk
提出日時 2018-10-11 19:32:23
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 11 ms / 3,000 ms
コード長 1,297 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 84,972 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-23 14:52:58
合計ジャッジ時間 2,011 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int h, w;
	cin>>h>>w;
	string s[50];
	int ct=0;
	for(int i=0; i<h; i++){
		cin>>s[i];
		for(int j=0; j<w; j++){
			if(s[i][j]=='#') ct++;
		}
	}
	if(ct%2==1 || ct==0){
		cout<<"NO"<<endl;
		return 0;
	}
	for(int x=0; x<h; x++){
		for(int y=-w+1; y<w; y++){
			if(x==0 && y==0) continue;
			bool used[50][50]={};
			bool nuee=0;
			for(int i=0; i<h; i++){
				for(int j=0; j<w; j++){
					if(s[i][j]=='.') continue;
					if(used[i][j]) continue;
					used[i][j]=1;
					int ct0=1;
					for(int k=1; ; k++){
						if(i+k*x<0 || i+k*x>=h || j+k*y<0 || j+k*y>=w || s[i+k*x][j+k*y]=='.') break;
						ct0++;
						used[i+k*x][j+k*y]=1;
					}
					for(int k=1; ; k++){
						if(i-k*x<0 || i-k*x>=h || j-k*y<0 || j-k*y>=w || s[i-k*x][j-k*y]=='.') break;
						ct0++;
						used[i-k*x][j-k*y]=1;
					}
					if(ct0%2){
						nuee=1;
						break;
					}
				}
				if(nuee) break;
			}
			if(!nuee){
				cout<<"YES"<<endl;
				return 0;
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}
0