結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
54,380 KB
testcase_01 AC 133 ms
54,160 KB
testcase_02 AC 137 ms
54,400 KB
testcase_03 AC 135 ms
54,104 KB
testcase_04 AC 138 ms
53,776 KB
testcase_05 AC 141 ms
54,084 KB
testcase_06 AC 141 ms
54,232 KB
testcase_07 AC 136 ms
53,972 KB
testcase_08 AC 139 ms
54,256 KB
testcase_09 AC 137 ms
54,040 KB
testcase_10 AC 139 ms
54,052 KB
testcase_11 AC 138 ms
54,056 KB
testcase_12 AC 136 ms
53,808 KB
testcase_13 AC 143 ms
55,864 KB
testcase_14 AC 142 ms
54,144 KB
testcase_15 AC 138 ms
53,540 KB
testcase_16 AC 135 ms
53,776 KB
testcase_17 AC 136 ms
53,920 KB
testcase_18 AC 140 ms
54,220 KB
testcase_19 AC 140 ms
54,048 KB
testcase_20 AC 150 ms
54,068 KB
testcase_21 AC 140 ms
54,264 KB
testcase_22 AC 136 ms
54,060 KB
testcase_23 AC 149 ms
54,284 KB
testcase_24 AC 1,359 ms
73,272 KB
testcase_25 AC 1,337 ms
73,436 KB
testcase_26 AC 1,360 ms
73,476 KB
testcase_27 AC 1,406 ms
73,680 KB
testcase_28 AC 1,377 ms
73,540 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 && a[y][x] == 1){
				search(y, x);
			}
		}
	}
}

0