Submission #343277


Source Code Expand

import java.util.*;

public class Main {

	
	public static void main(String[] arg){
		
		Scanner sc = new Scanner(System.in);
		int count = 0;
		char[][] c = new char[10][10];
		for(int i = 0;i < 10;i++){
			String s = sc.nextLine();
			for(int j = 0;j < 10;j++){
				c[i][j] = s.charAt(j);
				if(c[i][j] == 'o'){
					count++;
				}
			}
		}
		boolean ans = false;
		boolean first = true;
		flag:
		for(int i = 0;i < 10;i++)
		{
			for(int j = 0;j < 10;j++){
				if(first && c[i][j] == 'o'){
					first = false;
					ans = ri(c,i,j,count);
				}
				if(c[i][j] == 'x'){
					c[i][j] = 'o';
					ans = ri(c,i,j,count);
					c[i][j] = 'x';
				}
				if(ans){
					break flag;
				}
			}
		}
		if(ans)System.out.println("YES");
		else System.out.println("NO");
	}
	public static boolean ri(char[][] c,int a,int b,int count){
		ArrayList<Integer> ar1 = new ArrayList<Integer>();
		ArrayList<Integer> ar2 = new ArrayList<Integer>();
		int[] dx = {1,0,-1,0};
		int[] dy = {0,1,0,-1};
		ar1.add(a);
		ar2.add(b);
		int count2 = 0;
		char[][] check = new char[10][10];
		char[] ch = new char[1];
		//System.out.println(check[0][0]);
		while(ar1.size() > 0){
			int x = ar1.get(0);
			int y = ar2.get(0);
			//System.out.println(x);
			for(int i = 0;i < dx.length;i++){
				int nx = x + dx[i];
				int ny = y + dy[i];
				boolean jouken = (nx >= 0 && nx < 10 && ny >= 0 && ny < 10);
				//System.out.println(jouken);
				if(jouken && c[nx][ny] == 'o' && check[nx][ny] == ch[0]){
					ar1.add(nx);
					ar2.add(ny);
					check[nx][ny] = 'o';
					count2++;
				} else if(jouken && c[nx][ny] == 'x' && check[nx][ny] == ch[0]){
					check[nx][ny] = 'x';
				}
			}
			ar1.remove(0);
			ar2.remove(0);
		}
		//System.out.println(a + "   " + b + "   " + count2 + "  " + count);
		boolean ans = true;
		if(count == count2-1)ans = true;
		else ans=false;
		return ans;
	}
	static int find(int[]par,int x){
		if(par[x] == x)return par[x];
		else {
			return par[x] = find(par,par[x]);
		}
	}
	static void unite(int[] par,int[] rank,int x,int y){
		if(find(par,x) == find(par,y))return;
		else{
			if(rank[x] < rank[y]){
				par[x] = find(par,y);
			} else {
				par[y] = find(par,x);
				if(rank[x] == rank[y])rank[x]++;
			}
		}
	}
	
}

Submission Info

Submission Time
Task B - 埋め立て
User nknk
Language Java (OpenJDK 1.7.0)
Score 100
Code Size 2321 Byte
Status AC
Exec Time 365 ms
Memory 23384 KiB

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 348 ms 23208 KiB
00_sample_01.txt AC 350 ms 23312 KiB
00_sample_02.txt AC 362 ms 23312 KiB
10_rand_00.txt AC 365 ms 23356 KiB
10_rand_01.txt AC 347 ms 23092 KiB
10_rand_02.txt AC 347 ms 23268 KiB
10_rand_03.txt AC 349 ms 23256 KiB
10_rand_04.txt AC 344 ms 23268 KiB
10_rand_05.txt AC 353 ms 23216 KiB
10_rand_06.txt AC 343 ms 23236 KiB
10_rand_07.txt AC 352 ms 23220 KiB
10_rand_08.txt AC 347 ms 23208 KiB
10_rand_09.txt AC 348 ms 23236 KiB
10_rand_10.txt AC 352 ms 23312 KiB
10_rand_11.txt AC 354 ms 23248 KiB
10_rand_12.txt AC 351 ms 23384 KiB
10_rand_13.txt AC 341 ms 23200 KiB
10_rand_14.txt AC 355 ms 23244 KiB
10_rand_15.txt AC 349 ms 23252 KiB
10_rand_16.txt AC 344 ms 23188 KiB
10_rand_17.txt AC 345 ms 23332 KiB
10_rand_18.txt AC 352 ms 23240 KiB
10_rand_19.txt AC 348 ms 23292 KiB
10_rand_20.txt AC 348 ms 23272 KiB
10_rand_21.txt AC 345 ms 23340 KiB
10_rand_22.txt AC 352 ms 23212 KiB
10_rand_23.txt AC 342 ms 23228 KiB
10_rand_24.txt AC 350 ms 23224 KiB
10_rand_25.txt AC 346 ms 23216 KiB
10_rand_26.txt AC 351 ms 23220 KiB
10_rand_27.txt AC 343 ms 23244 KiB
10_rand_28.txt AC 351 ms 23092 KiB
10_rand_29.txt AC 354 ms 23256 KiB