結果

問題 No.697 池の数はいくつか
ユーザー tentententen
提出日時 2020-09-03 13:00:21
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,157 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 77,728 KB
実行使用メモリ 811,044 KB
最終ジャッジ日時 2024-05-04 07:07:40
合計ジャッジ時間 16,514 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
54,080 KB
testcase_01 AC 114 ms
53,964 KB
testcase_02 AC 116 ms
54,040 KB
testcase_03 AC 117 ms
54,096 KB
testcase_04 AC 117 ms
54,248 KB
testcase_05 AC 104 ms
52,688 KB
testcase_06 AC 105 ms
52,800 KB
testcase_07 AC 105 ms
52,788 KB
testcase_08 AC 128 ms
54,076 KB
testcase_09 AC 121 ms
53,640 KB
testcase_10 AC 107 ms
52,948 KB
testcase_11 AC 129 ms
53,892 KB
testcase_12 AC 123 ms
53,964 KB
testcase_13 AC 121 ms
54,028 KB
testcase_14 AC 108 ms
52,696 KB
testcase_15 AC 125 ms
54,296 KB
testcase_16 AC 105 ms
52,976 KB
testcase_17 AC 104 ms
52,904 KB
testcase_18 AC 117 ms
53,720 KB
testcase_19 AC 118 ms
54,096 KB
testcase_20 AC 114 ms
54,112 KB
testcase_21 AC 104 ms
52,736 KB
testcase_22 AC 117 ms
53,952 KB
testcase_23 AC 108 ms
52,940 KB
testcase_24 AC 402 ms
58,532 KB
testcase_25 AC 355 ms
59,272 KB
testcase_26 AC 384 ms
58,532 KB
testcase_27 AC 354 ms
58,620 KB
testcase_28 AC 384 ms
58,652 KB
testcase_29 MLE -
testcase_30 AC 947 ms
69,652 KB
testcase_31 MLE -
testcase_32 AC 949 ms
69,708 KB
testcase_33 AC 976 ms
69,440 KB
testcase_34 AC 945 ms
69,728 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];
    	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]) {
    	            count++;
    	            setUse(i, j, field);
    	        }
    	    }
    	}
    	System.out.println(count);
	}
	
	static void setUse(int r, int c, boolean[][] field) {
	    if (field[r][c]) {
	        field[r][c] = false;
	        if (field[r - 1][c]) {
	            setUse(r - 1, c, field);
	        }
	        if (field[r + 1][c]) {
	            setUse(r + 1, c, field);
	        }
	        if (field[r][c - 1]) {
	            setUse(r, c - 1, field);
	        }
	        if (field[r][c + 1]) {
	            setUse(r, c + 1, field);
	        }
	    }
	}
}
0