結果

問題 No.697 池の数はいくつか
ユーザー htensaihtensai
提出日時 2019-12-19 11:33:44
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,189 bytes
コンパイル時間 2,496 ms
コンパイル使用メモリ 76,764 KB
実行使用メモリ 835,420 KB
最終ジャッジ日時 2024-05-04 06:46:00
合計ジャッジ時間 9,720 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
36,472 KB
testcase_01 AC 44 ms
36,704 KB
testcase_02 AC 43 ms
36,600 KB
testcase_03 AC 45 ms
36,860 KB
testcase_04 AC 46 ms
36,956 KB
testcase_05 AC 43 ms
36,784 KB
testcase_06 AC 44 ms
36,768 KB
testcase_07 AC 43 ms
36,704 KB
testcase_08 AC 43 ms
36,768 KB
testcase_09 AC 43 ms
36,596 KB
testcase_10 AC 42 ms
36,736 KB
testcase_11 AC 43 ms
36,980 KB
testcase_12 AC 43 ms
36,628 KB
testcase_13 AC 42 ms
36,968 KB
testcase_14 AC 43 ms
36,956 KB
testcase_15 AC 43 ms
36,596 KB
testcase_16 AC 44 ms
36,472 KB
testcase_17 AC 43 ms
36,688 KB
testcase_18 AC 44 ms
36,816 KB
testcase_19 AC 47 ms
36,956 KB
testcase_20 AC 46 ms
36,768 KB
testcase_21 AC 46 ms
36,880 KB
testcase_22 AC 46 ms
36,480 KB
testcase_23 AC 45 ms
37,000 KB
testcase_24 AC 433 ms
48,304 KB
testcase_25 AC 397 ms
48,088 KB
testcase_26 AC 396 ms
48,176 KB
testcase_27 AC 423 ms
48,200 KB
testcase_28 AC 400 ms
48,412 KB
testcase_29 MLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static boolean[][] field;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        int h = Integer.parseInt(first[0]);
        int w = Integer.parseInt(first[1]);
        field = new boolean[h + 2][w + 2];
        for (int i = 1; i <= h; i++) {
            String[] line = br.readLine().split(" ", w);
            for (int j = 1; j <= w; j++) {
                field[i][j] = line[j - 1].charAt(0) == '1';
            }
        }
        int count = 0;
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                if (field[i][j]) {
                    setCell(i, j);
                    count++;
                }
            }
        }
        System.out.println(count);
    }
    
    static void setCell(int hh, int ww) {
        if (!field[hh][ww]) {
            return;
        }
        field[hh][ww] = false;
        setCell(hh - 1, ww);
        setCell(hh + 1, ww);
        setCell(hh, ww - 1);
        setCell(hh, ww + 1);
    }
}
0