Submission #299071


Source Code Expand

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	static boolean[][] area = new boolean[10][10];

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		for (int i = 0; i < 10; i++) {
			char[] temp = scanner.next().toCharArray();
			for (int j = 0; j < 10; j++) {
				area[i][j] = (temp[j] == 'o');
			}
		}

		boolean flag = false;
		for (int i = 0; i < 10; i++) {
			if (flag)
				break;
			for (int j = 0; j < 10; j++) {
				if (flag)
					break;
				if (!area[i][j]) {
					area[i][j] = true;
					if (goalcheck()) {
						flag = true;
						break;
					}
					area[i][j] = false;
				}
			}
		}

		System.out.println(flag ? "YES" : "NO");
	}

	private static boolean goalcheck() {
		LinkedList<int[]> q = new LinkedList<int[]>();
		HashSet<int[]> checked = new HashSet<int[]>();
		boolean flag = false;

		for (int i = 0; i < 10; i++) {
			if (flag)
				break;
			for (int j = 0; j < 10; j++) {
				if (flag)
					break;
				if (area[i][j]) {
					flag = true;
					int[] temp = { i, j };
					q.add(temp);
					checked.add(temp);
					while (!q.isEmpty()) {
						int[] t = q.pop();
						checked.add(t);

						int x = t[0];
						int y = t[1];
						int x2 = t[0] + 1;
						int y2 = t[1] + 1;
						int x3 = t[0] - 1;
						int y3 = t[1] - 1;

						if (x2 < 10 && area[x2][y]) {
							int[] temp2 = { x2, y };
							if (!checkmas(temp2, checked)) {
								q.add(temp2);
							}
						}

						if (y2 < 10 && area[x][y2]) {
							int[] temp2 = { x, y2 };
							if (!checkmas(temp2, checked)) {
								q.add(temp2);
							}
						}

						if (x3 >= 0 && area[x3][y]) {
							int[] temp2 = { x3, y };
							if (!checkmas(temp2, checked)) {
								q.add(temp2);
							}
						}

						if (y3 >= 0 && area[x][y3]) {
							int[] temp2 = { x, y3 };
							if (!checkmas(temp2, checked)) {
								q.add(temp2);
							}
						}
					}
				}
			}
		}

		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (area[i][j]) {
					int[] temp = { i, j };
					if (!checkmas(temp, checked)) {
						return false;
					}
				}
			}
		}

		return true;
	}

	static boolean checkmas(int[] t, HashSet<int[]> checked) {
		for (int[] check : checked) {
			if (t[0] == check[0] && t[1] == check[1]) {
				return true;
			}
		}
		return false;
	}
}

Submission Info

Submission Time
Task B - 埋め立て
User yumechi
Language Java (OpenJDK 1.7.0)
Score 100
Code Size 2479 Byte
Status AC
Exec Time 659 ms
Memory 37248 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 33
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 10_rand_00.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 10_rand_06.txt, 10_rand_07.txt, 10_rand_08.txt, 10_rand_09.txt, 10_rand_10.txt, 10_rand_11.txt, 10_rand_12.txt, 10_rand_13.txt, 10_rand_14.txt, 10_rand_15.txt, 10_rand_16.txt, 10_rand_17.txt, 10_rand_18.txt, 10_rand_19.txt, 10_rand_20.txt, 10_rand_21.txt, 10_rand_22.txt, 10_rand_23.txt, 10_rand_24.txt, 10_rand_25.txt, 10_rand_26.txt, 10_rand_27.txt, 10_rand_28.txt, 10_rand_29.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 382 ms 24136 KB
00_sample_01.txt AC 384 ms 24244 KB
00_sample_02.txt AC 354 ms 23096 KB
10_rand_00.txt AC 659 ms 37248 KB
10_rand_01.txt AC 346 ms 23092 KB
10_rand_02.txt AC 445 ms 24640 KB
10_rand_03.txt AC 347 ms 23096 KB
10_rand_04.txt AC 370 ms 23636 KB
10_rand_05.txt AC 499 ms 29516 KB
10_rand_06.txt AC 354 ms 23196 KB
10_rand_07.txt AC 558 ms 34164 KB
10_rand_08.txt AC 415 ms 24948 KB
10_rand_09.txt AC 418 ms 24940 KB
10_rand_10.txt AC 440 ms 25760 KB
10_rand_11.txt AC 482 ms 26740 KB
10_rand_12.txt AC 403 ms 23616 KB
10_rand_13.txt AC 403 ms 24152 KB
10_rand_14.txt AC 515 ms 31604 KB
10_rand_15.txt AC 399 ms 24360 KB
10_rand_16.txt AC 372 ms 23644 KB
10_rand_17.txt AC 358 ms 23068 KB
10_rand_18.txt AC 480 ms 27860 KB
10_rand_19.txt AC 391 ms 24372 KB
10_rand_20.txt AC 452 ms 25092 KB
10_rand_21.txt AC 353 ms 23188 KB
10_rand_22.txt AC 533 ms 31896 KB
10_rand_23.txt AC 592 ms 32652 KB
10_rand_24.txt AC 452 ms 26336 KB
10_rand_25.txt AC 367 ms 24060 KB
10_rand_26.txt AC 424 ms 25520 KB
10_rand_27.txt AC 383 ms 24008 KB
10_rand_28.txt AC 457 ms 26104 KB
10_rand_29.txt AC 574 ms 34192 KB