結果

問題 No.697 池の数はいくつか
ユーザー htensaihtensai
提出日時 2019-12-19 11:33:44
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,189 bytes
コンパイル時間 3,177 ms
コンパイル使用メモリ 73,724 KB
実行使用メモリ 837,840 KB
最終ジャッジ日時 2023-08-16 23:22:34
合計ジャッジ時間 11,871 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,400 KB
testcase_01 AC 46 ms
47,328 KB
testcase_02 AC 47 ms
49,352 KB
testcase_03 AC 46 ms
49,152 KB
testcase_04 AC 45 ms
49,320 KB
testcase_05 AC 46 ms
49,552 KB
testcase_06 AC 47 ms
49,608 KB
testcase_07 AC 46 ms
49,264 KB
testcase_08 AC 45 ms
49,432 KB
testcase_09 AC 46 ms
49,368 KB
testcase_10 AC 46 ms
49,320 KB
testcase_11 AC 47 ms
49,156 KB
testcase_12 AC 45 ms
49,312 KB
testcase_13 AC 46 ms
49,160 KB
testcase_14 AC 46 ms
49,212 KB
testcase_15 AC 46 ms
49,160 KB
testcase_16 AC 45 ms
49,260 KB
testcase_17 AC 47 ms
49,388 KB
testcase_18 AC 46 ms
49,164 KB
testcase_19 AC 46 ms
49,712 KB
testcase_20 AC 45 ms
49,240 KB
testcase_21 AC 46 ms
49,256 KB
testcase_22 AC 45 ms
49,260 KB
testcase_23 AC 46 ms
49,560 KB
testcase_24 AC 458 ms
58,444 KB
testcase_25 AC 437 ms
57,924 KB
testcase_26 AC 468 ms
58,504 KB
testcase_27 AC 457 ms
58,336 KB
testcase_28 AC 461 ms
57,996 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