結果

問題 No.697 池の数はいくつか
ユーザー tentententen
提出日時 2020-09-03 12:57:02
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,360 bytes
コンパイル時間 1,926 ms
コンパイル使用メモリ 76,940 KB
実行使用メモリ 752,396 KB
最終ジャッジ日時 2024-05-04 07:06:08
合計ジャッジ時間 16,945 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
54,092 KB
testcase_01 AC 109 ms
52,940 KB
testcase_02 AC 104 ms
52,572 KB
testcase_03 AC 117 ms
53,972 KB
testcase_04 AC 110 ms
52,988 KB
testcase_05 AC 123 ms
54,188 KB
testcase_06 AC 126 ms
54,076 KB
testcase_07 AC 106 ms
52,960 KB
testcase_08 AC 108 ms
52,796 KB
testcase_09 AC 115 ms
54,240 KB
testcase_10 AC 105 ms
52,956 KB
testcase_11 AC 106 ms
52,936 KB
testcase_12 AC 121 ms
54,172 KB
testcase_13 AC 122 ms
54,348 KB
testcase_14 AC 118 ms
54,080 KB
testcase_15 AC 120 ms
53,976 KB
testcase_16 AC 120 ms
54,152 KB
testcase_17 AC 125 ms
54,112 KB
testcase_18 AC 123 ms
54,348 KB
testcase_19 AC 125 ms
54,124 KB
testcase_20 AC 122 ms
53,876 KB
testcase_21 AC 128 ms
54,284 KB
testcase_22 AC 114 ms
52,816 KB
testcase_23 AC 121 ms
54,000 KB
testcase_24 AC 384 ms
60,544 KB
testcase_25 AC 387 ms
60,536 KB
testcase_26 AC 400 ms
61,024 KB
testcase_27 AC 397 ms
60,620 KB
testcase_28 AC 389 ms
60,600 KB
testcase_29 MLE -
testcase_30 AC 1,040 ms
80,196 KB
testcase_31 MLE -
testcase_32 AC 1,037 ms
80,108 KB
testcase_33 AC 1,035 ms
80,192 KB
testcase_34 AC 1,020 ms
79,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int h = sc.nextInt();
    	int w = sc.nextInt();
    	sc.nextLine();
    	boolean[][] field = new boolean[h + 2][w + 2];
    	boolean[][] used = new boolean[h + 2][w + 2];
    	for (int i = 1; i <= h; i++) {
    	    char[] arr = sc.nextLine().toCharArray();
    	    for (int j = 1; j <= w; j++) {
    	        field[i][j] = (arr[(j - 1) * 2] == '1');
    	    }
    	}
    	int count = 0;
    	for (int i = 1; i <= h; i++) {
    	    for (int j = 1; j <= w; j++) {
    	        if (field[i][j] && !used[i][j]) {
    	            count++;
    	            setUse(i, j, field, used);
    	        }
    	    }
    	}
    	System.out.println(count);
	}
	
	static void setUse(int r, int c, boolean[][] field, boolean[][] used) {
	    if (field[r][c] && !used[r][c]) {
	        used[r][c] = true;
	        if (field[r - 1][c] && !used[r - 1][c]) {
	            setUse(r - 1, c, field, used);
	        }
	        if (field[r + 1][c] && !used[r + 1][c]) {
	            setUse(r + 1, c, field, used);
	        }
	        if (field[r][c - 1] && !used[r][c - 1]) {
	            setUse(r, c - 1, field, used);
	        }
	        if (field[r][c + 1] && !used[r][c + 1]) {
	            setUse(r, c + 1, field, used);
	        }
	    }
	}
}
0