結果

問題 No.697 池の数はいくつか
ユーザー tentententen
提出日時 2020-09-03 11:51:37
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,019 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 76,864 KB
実行使用メモリ 820,748 KB
最終ジャッジ日時 2024-05-04 07:05:47
合計ジャッジ時間 39,410 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
52,464 KB
testcase_01 AC 99 ms
52,776 KB
testcase_02 AC 95 ms
52,440 KB
testcase_03 AC 109 ms
54,020 KB
testcase_04 AC 103 ms
52,812 KB
testcase_05 AC 109 ms
53,796 KB
testcase_06 AC 112 ms
54,156 KB
testcase_07 AC 99 ms
53,052 KB
testcase_08 AC 117 ms
54,292 KB
testcase_09 AC 114 ms
54,052 KB
testcase_10 AC 110 ms
54,016 KB
testcase_11 AC 99 ms
53,000 KB
testcase_12 AC 101 ms
54,524 KB
testcase_13 AC 115 ms
53,672 KB
testcase_14 AC 111 ms
53,780 KB
testcase_15 AC 101 ms
52,872 KB
testcase_16 AC 106 ms
53,768 KB
testcase_17 AC 115 ms
54,008 KB
testcase_18 AC 113 ms
53,916 KB
testcase_19 AC 99 ms
52,160 KB
testcase_20 AC 119 ms
53,936 KB
testcase_21 AC 111 ms
53,808 KB
testcase_22 AC 94 ms
52,604 KB
testcase_23 AC 122 ms
54,240 KB
testcase_24 AC 1,075 ms
70,940 KB
testcase_25 AC 1,103 ms
69,096 KB
testcase_26 AC 1,081 ms
69,344 KB
testcase_27 AC 1,116 ms
69,040 KB
testcase_28 AC 1,138 ms
68,928 KB
testcase_29 MLE -
testcase_30 AC 4,210 ms
83,588 KB
testcase_31 MLE -
testcase_32 AC 4,245 ms
84,452 KB
testcase_33 AC 4,232 ms
81,264 KB
testcase_34 AC 4,237 ms
82,876 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();
    	boolean[][] field = new boolean[h + 2][w + 2];
    	for (int i = 1; i <= h; i++) {
    	    for (int j = 1; j <= w; j++) {
    	        field[i][j] = (sc.nextInt() == 1);
    	    }
    	}
    	boolean[][] used = new boolean[h + 2][w + 2];
    	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;
	        setUse(r - 1, c, field, used);
	        setUse(r + 1, c, field, used);
	        setUse(r, c - 1, field, used);
	        setUse(r, c + 1, field, used);
	    }
	}
}
0