結果

問題 No.697 池の数はいくつか
ユーザー htensaihtensai
提出日時 2019-12-19 11:36:55
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,176 bytes
コンパイル時間 3,765 ms
コンパイル使用メモリ 74,216 KB
実行使用メモリ 830,240 KB
最終ジャッジ日時 2023-08-16 23:23:31
合計ジャッジ時間 10,416 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,184 KB
testcase_01 AC 46 ms
49,348 KB
testcase_02 AC 45 ms
49,212 KB
testcase_03 AC 47 ms
49,160 KB
testcase_04 AC 45 ms
47,412 KB
testcase_05 AC 46 ms
49,404 KB
testcase_06 AC 46 ms
49,360 KB
testcase_07 AC 47 ms
49,160 KB
testcase_08 AC 47 ms
49,656 KB
testcase_09 AC 46 ms
49,364 KB
testcase_10 AC 46 ms
49,392 KB
testcase_11 AC 49 ms
49,480 KB
testcase_12 AC 48 ms
49,416 KB
testcase_13 AC 47 ms
49,384 KB
testcase_14 AC 45 ms
49,212 KB
testcase_15 AC 47 ms
49,408 KB
testcase_16 AC 46 ms
49,472 KB
testcase_17 AC 47 ms
49,304 KB
testcase_18 AC 45 ms
49,212 KB
testcase_19 AC 45 ms
49,640 KB
testcase_20 AC 46 ms
49,216 KB
testcase_21 AC 46 ms
47,280 KB
testcase_22 AC 45 ms
49,304 KB
testcase_23 AC 46 ms
49,160 KB
testcase_24 AC 252 ms
56,852 KB
testcase_25 AC 249 ms
57,168 KB
testcase_26 AC 260 ms
57,228 KB
testcase_27 AC 250 ms
57,260 KB
testcase_28 AC 242 ms
57,548 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();
            for (int j = 1; j <= w; j++) {
                field[i][j] = line.charAt((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]) {
                    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