結果

問題 No.179 塗り分け
ユーザー 37zigen37zigen
提出日時 2020-02-19 14:35:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 270 ms / 3,000 ms
コード長 1,471 bytes
コンパイル時間 2,217 ms
コンパイル使用メモリ 74,808 KB
実行使用メモリ 58,576 KB
最終ジャッジ日時 2023-09-30 21:24:19
合計ジャッジ時間 11,376 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,468 KB
testcase_01 AC 125 ms
56,220 KB
testcase_02 AC 125 ms
55,244 KB
testcase_03 AC 125 ms
56,184 KB
testcase_04 AC 125 ms
55,768 KB
testcase_05 AC 162 ms
58,280 KB
testcase_06 AC 127 ms
55,556 KB
testcase_07 AC 133 ms
55,544 KB
testcase_08 AC 167 ms
55,964 KB
testcase_09 AC 195 ms
58,380 KB
testcase_10 AC 131 ms
55,488 KB
testcase_11 AC 134 ms
55,232 KB
testcase_12 AC 225 ms
58,564 KB
testcase_13 AC 126 ms
55,788 KB
testcase_14 AC 131 ms
55,796 KB
testcase_15 AC 126 ms
56,132 KB
testcase_16 AC 123 ms
55,764 KB
testcase_17 AC 125 ms
56,060 KB
testcase_18 AC 146 ms
55,648 KB
testcase_19 AC 146 ms
55,176 KB
testcase_20 AC 221 ms
58,576 KB
testcase_21 AC 215 ms
58,408 KB
testcase_22 AC 203 ms
58,136 KB
testcase_23 AC 134 ms
54,024 KB
testcase_24 AC 210 ms
58,388 KB
testcase_25 AC 132 ms
55,808 KB
testcase_26 AC 188 ms
58,240 KB
testcase_27 AC 229 ms
58,360 KB
testcase_28 AC 212 ms
57,524 KB
testcase_29 AC 248 ms
56,220 KB
testcase_30 AC 231 ms
58,160 KB
testcase_31 AC 270 ms
58,448 KB
testcase_32 AC 168 ms
58,076 KB
testcase_33 AC 254 ms
58,220 KB
testcase_34 AC 224 ms
58,088 KB
testcase_35 AC 263 ms
58,244 KB
testcase_36 AC 124 ms
56,176 KB
testcase_37 AC 124 ms
56,492 KB
testcase_38 AC 123 ms
55,692 KB
testcase_39 AC 122 ms
55,956 KB
testcase_40 AC 122 ms
56,164 KB
testcase_41 AC 123 ms
55,816 KB
testcase_42 AC 125 ms
55,480 KB
testcase_43 AC 148 ms
57,536 KB
testcase_44 AC 166 ms
58,456 KB
testcase_45 AC 125 ms
56,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void solve(int H,int W,char[][] m) {
		for(int dh=0;dh<H;++dh) {
			for(int dw=0;dw<W;++dw) {
				if(dh==0&&dw==0)continue;
				boolean flag=true;
				int[][] rec=new int[H][W];
				for(int h=0;h<H;++h) {
					for(int w=0;w<W;++w) {
						if(m[h][w]=='.')continue;
						if(rec[h][w]!=0)continue;
						int nh=h+dh;
						int nw=w+dw;
						if(nh>=H||nw>=W) {
							flag=false;
							continue;
						}
						if(rec[nh][nw]==2) {
							flag=false;
							continue;
						}
						flag&=m[nh][nw]=='#';
						rec[h][w]=1;
						rec[nh][nw]=2;
					}
				}
				if(flag) {
					System.out.println("YES");
					System.exit(0);
				}
			}
		}
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		char[][] m=new char[H][W];
		boolean all=true;
		for(int i=0;i<H;++i) {
			m[i]=sc.next().toCharArray();
			for(int j=0;j<m[i].length;++j)all&=m[i][j]=='.';
		}
		if(all) {
			System.out.println("NO");
			return;
		}
		solve(H,W,m);
		{
			for(int h=0;h<H;++h) {
				int s=0;
				int t=W-1;
				while(s<t) {
					m[h][s]^=m[h][t];
					m[h][t]^=m[h][s];
					m[h][s]^=m[h][t];
					++s;--t;
				}
			}
		}
		solve(H,W,m);
		System.out.println("NO");
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}
0