結果

問題 No.697 池の数はいくつか
ユーザー htensaihtensai
提出日時 2019-12-19 11:36:55
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,176 bytes
コンパイル時間 2,480 ms
コンパイル使用メモリ 77,240 KB
実行使用メモリ 831,948 KB
最終ジャッジ日時 2024-05-04 06:46:49
合計ジャッジ時間 8,489 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
50,176 KB
testcase_01 AC 46 ms
49,844 KB
testcase_02 AC 47 ms
50,140 KB
testcase_03 AC 47 ms
50,188 KB
testcase_04 AC 46 ms
50,092 KB
testcase_05 AC 46 ms
50,112 KB
testcase_06 AC 45 ms
49,820 KB
testcase_07 AC 46 ms
49,912 KB
testcase_08 AC 46 ms
50,096 KB
testcase_09 AC 46 ms
50,056 KB
testcase_10 AC 48 ms
50,180 KB
testcase_11 AC 49 ms
49,820 KB
testcase_12 AC 47 ms
50,080 KB
testcase_13 AC 47 ms
50,248 KB
testcase_14 AC 49 ms
49,804 KB
testcase_15 AC 48 ms
49,908 KB
testcase_16 AC 48 ms
50,092 KB
testcase_17 AC 48 ms
50,072 KB
testcase_18 AC 48 ms
50,220 KB
testcase_19 AC 47 ms
49,832 KB
testcase_20 AC 45 ms
50,084 KB
testcase_21 AC 47 ms
50,056 KB
testcase_22 AC 52 ms
50,136 KB
testcase_23 AC 46 ms
50,296 KB
testcase_24 AC 227 ms
56,100 KB
testcase_25 AC 227 ms
56,292 KB
testcase_26 AC 218 ms
57,276 KB
testcase_27 AC 231 ms
56,184 KB
testcase_28 AC 226 ms
55,952 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