結果

問題 No.697 池の数はいくつか
ユーザー Daigo HIROOKADaigo HIROOKA
提出日時 2018-06-23 02:05:26
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 792 bytes
コンパイル時間 4,504 ms
コンパイル使用メモリ 77,564 KB
実行使用メモリ 832,388 KB
最終ジャッジ日時 2024-05-04 05:58:13
合計ジャッジ時間 23,904 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
53,864 KB
testcase_01 AC 139 ms
53,996 KB
testcase_02 AC 140 ms
54,072 KB
testcase_03 AC 138 ms
54,360 KB
testcase_04 AC 143 ms
53,776 KB
testcase_05 AC 139 ms
54,152 KB
testcase_06 AC 143 ms
54,216 KB
testcase_07 AC 143 ms
54,224 KB
testcase_08 AC 137 ms
54,184 KB
testcase_09 AC 139 ms
53,968 KB
testcase_10 AC 141 ms
53,892 KB
testcase_11 AC 140 ms
53,704 KB
testcase_12 AC 140 ms
54,112 KB
testcase_13 AC 143 ms
54,120 KB
testcase_14 AC 139 ms
54,020 KB
testcase_15 AC 140 ms
54,320 KB
testcase_16 AC 136 ms
54,124 KB
testcase_17 AC 140 ms
54,252 KB
testcase_18 AC 140 ms
53,964 KB
testcase_19 AC 140 ms
54,232 KB
testcase_20 AC 145 ms
54,020 KB
testcase_21 AC 141 ms
53,888 KB
testcase_22 AC 138 ms
54,264 KB
testcase_23 AC 146 ms
54,148 KB
testcase_24 AC 1,354 ms
73,780 KB
testcase_25 AC 1,340 ms
73,676 KB
testcase_26 AC 1,363 ms
73,340 KB
testcase_27 AC 1,375 ms
73,460 KB
testcase_28 AC 1,392 ms
72,912 KB
testcase_29 MLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class No697{

	static int H, W;
	static int[][] a;
	static int[] dx = {0, 1, 0, -1};
	static int[] dy = {-1, 0, 1, 0};
		
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		H = sc.nextInt();
		W = sc.nextInt();

		a = new int[H][W];
		for(int h = 0; h < H; h++){
			for(int w = 0; w < W; w++){
				a[h][w] = sc.nextInt();
			}
		}

		int ans = 0;
		for(int h = 0; h < H; h++){
			for(int w = 0; w < W; w++){
				if(a[h][w] == 1){
					search(h, w);
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
	private static void search(int h, int w){
		a[h][w] = 0;
		for(int i = 0; i < 4; i++){
			int x = w+dx[i], y = h+dy[i];
			if(x >= 0 && x < W && y >= 0 && y < H){
				if(a[y][x] == 1){
					search(y, x);
				}
			}
		}
	}
}

0