結果

問題 No.179 塗り分け
ユーザー はまやんはまやん
提出日時 2015-06-19 16:21:30
言語 Java
(openjdk 23)
結果
AC  
実行時間 292 ms / 3,000 ms
コード長 1,794 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 78,384 KB
実行使用メモリ 47,732 KB
最終ジャッジ日時 2024-07-23 14:30:38
合計ジャッジ時間 11,405 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.awt.Point;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	
	static int h, w;
	static int[][] map;
	static int count;
	
	static void start()
	{
		for(int dy = 0;dy < h;dy++)
			for(int dx = 0;dx < w;dx++)
			{
				if(dx == 0 && dy == 0) continue;
				
				int[][] mapp = new int[h][w];
				int cc = 0;
				for(int y = 0;y < h;y++)
					for(int x= 0;x < w;x++)
						mapp[y][x] = 0;
				
				for(int y = 0;y < (h-dy);y++)
					for(int x = 0;x < (w-dx);x++)
					{
						if(mapp[y][x] == 1) continue;
						if(map[y][x] == 0) continue;
						if(map[y+dy][x+dx] == 0) continue;
						
						mapp[y][x] = 1;
						mapp[y+dy][x+dx] = 1;
						cc += 2;
						if(cc == count)
						{
							System.out.println("YES");
							return;
						}
					}
				
				cc = 0;
				for(int y = 0;y < h;y++)
					for(int x= 0;x < w;x++)
						mapp[y][x] = 0;
				
				for(int y = h-1;y >= dy;y--)
					for(int x = 0;x < (w-dx);x++)
					{
						if(mapp[y][x] == 1) continue;
						if(map[y][x] == 0) continue;
						if(map[y-dy][x+dx] == 0) continue;
						
						mapp[y][x] = 1;
						mapp[y-dy][x+dx] = 1;
						cc += 2;
						if(cc == count)
						{
							System.out.println("YES");
							return;
						}
					}
			}
		
		System.out.println("NO");
	}
	
	public static void main(String[] args)
	{
		Scanner sca = new Scanner(System.in);
		
		while(true)
		{
			h = sca.nextInt();
			w = sca.nextInt();
			
			map = new int[h][w];
			count = 0;
			for(int y = 0;y < h;y++)
			{
				String str = sca.next();
				for(int x = 0;x < w;x++)
				{
					if(str.charAt(x) == '#')
					{
						map[y][x] = 1;
						count++;
					}
					else
					{
						map[y][x] = 0;
					}
				}
			}
			
			start();
			break;
		}
	}
}
0