結果

問題 No.179 塗り分け
ユーザー tutuztutuz
提出日時 2018-09-14 21:21:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 277 ms / 3,000 ms
コード長 3,751 bytes
コンパイル時間 4,287 ms
コンパイル使用メモリ 74,276 KB
実行使用メモリ 55,740 KB
最終ジャッジ日時 2023-09-30 21:05:48
合計ジャッジ時間 10,941 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,508 KB
testcase_01 AC 46 ms
49,884 KB
testcase_02 AC 46 ms
49,516 KB
testcase_03 AC 47 ms
49,684 KB
testcase_04 AC 46 ms
49,604 KB
testcase_05 AC 47 ms
49,884 KB
testcase_06 AC 65 ms
51,948 KB
testcase_07 AC 48 ms
49,500 KB
testcase_08 AC 48 ms
49,604 KB
testcase_09 AC 54 ms
49,596 KB
testcase_10 AC 107 ms
53,544 KB
testcase_11 AC 103 ms
53,692 KB
testcase_12 AC 219 ms
54,112 KB
testcase_13 AC 48 ms
49,508 KB
testcase_14 AC 47 ms
49,488 KB
testcase_15 AC 45 ms
49,716 KB
testcase_16 AC 46 ms
49,540 KB
testcase_17 AC 45 ms
49,912 KB
testcase_18 AC 148 ms
53,848 KB
testcase_19 AC 143 ms
53,608 KB
testcase_20 AC 48 ms
50,152 KB
testcase_21 AC 48 ms
49,548 KB
testcase_22 AC 249 ms
54,028 KB
testcase_23 AC 165 ms
54,136 KB
testcase_24 AC 223 ms
53,692 KB
testcase_25 AC 166 ms
53,468 KB
testcase_26 AC 147 ms
53,604 KB
testcase_27 AC 253 ms
53,636 KB
testcase_28 AC 166 ms
53,452 KB
testcase_29 AC 263 ms
53,696 KB
testcase_30 AC 129 ms
53,444 KB
testcase_31 AC 272 ms
53,484 KB
testcase_32 AC 142 ms
54,180 KB
testcase_33 AC 254 ms
55,740 KB
testcase_34 AC 155 ms
53,448 KB
testcase_35 AC 277 ms
53,816 KB
testcase_36 AC 46 ms
49,540 KB
testcase_37 AC 45 ms
49,504 KB
testcase_38 AC 46 ms
49,580 KB
testcase_39 AC 46 ms
49,540 KB
testcase_40 AC 46 ms
49,528 KB
testcase_41 AC 45 ms
49,608 KB
testcase_42 AC 46 ms
49,532 KB
testcase_43 AC 74 ms
51,392 KB
testcase_44 AC 113 ms
54,040 KB
testcase_45 AC 51 ms
49,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		int n, m;
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			n = in.nextInt(); m = in.nextInt();
			char[][] s = new char[n][m];
			for (int i = 0; i < n; i++) {
				s[i] = in.nextString().toCharArray();
			}

			int cnt = 0;
			for (char[] cs : s) {
				for (char c : cs) {
					cnt += c == '#' ? 1 : 0;
				}
			}

			if (cnt % 2 == 1 || cnt == 0) {
				out.println("NO");
				return;
			}

			for (int i = -n+1; i < n; i++) {
				for (int j = -m+1; j < m; j++) {

					if (check(s, i, j, cnt)) {
						out.println("YES");
						return;
					}
				}
			}

			out.println("NO");

		}

		boolean check(char[][] s, int i, int j, int count) {

			int tmp = 0;
			boolean[][] used = new boolean[n][m];
			for (int a = 0; a < n; a++) {
				for (int b = 0; b < m; b++) {
					if (a + i < 0 || b + j < 0 || a + i >= n || b + j >= m) {
						continue;
					}
					if (used[a][b] || used[a+i][b+j] || s[a][b] == '.' || s[a+i][b+j] == '.') {
						continue;
					}
					used[a][b] = used[a+i][b+j] = true;
					tmp += 2;
				}
			}

			return count == tmp;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}
0