結果
問題 | No.697 池の数はいくつか |
ユーザー | tenten |
提出日時 | 2020-12-04 14:04:14 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,080 ms / 6,000 ms |
コード長 | 1,882 bytes |
コンパイル時間 | 2,963 ms |
コンパイル使用メモリ | 78,332 KB |
実行使用メモリ | 69,780 KB |
最終ジャッジ日時 | 2024-04-25 20:57:21 |
合計ジャッジ時間 | 13,700 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
50,320 KB |
testcase_01 | AC | 52 ms
50,316 KB |
testcase_02 | AC | 53 ms
50,112 KB |
testcase_03 | AC | 52 ms
50,428 KB |
testcase_04 | AC | 49 ms
50,088 KB |
testcase_05 | AC | 47 ms
49,968 KB |
testcase_06 | AC | 49 ms
49,928 KB |
testcase_07 | AC | 49 ms
50,304 KB |
testcase_08 | AC | 49 ms
50,432 KB |
testcase_09 | AC | 51 ms
50,092 KB |
testcase_10 | AC | 52 ms
50,164 KB |
testcase_11 | AC | 50 ms
50,032 KB |
testcase_12 | AC | 50 ms
50,344 KB |
testcase_13 | AC | 50 ms
50,376 KB |
testcase_14 | AC | 50 ms
50,320 KB |
testcase_15 | AC | 50 ms
49,900 KB |
testcase_16 | AC | 53 ms
50,232 KB |
testcase_17 | AC | 51 ms
50,312 KB |
testcase_18 | AC | 51 ms
50,384 KB |
testcase_19 | AC | 54 ms
50,040 KB |
testcase_20 | AC | 52 ms
49,872 KB |
testcase_21 | AC | 52 ms
50,284 KB |
testcase_22 | AC | 52 ms
50,356 KB |
testcase_23 | AC | 53 ms
50,052 KB |
testcase_24 | AC | 479 ms
59,228 KB |
testcase_25 | AC | 438 ms
59,100 KB |
testcase_26 | AC | 483 ms
59,588 KB |
testcase_27 | AC | 461 ms
58,912 KB |
testcase_28 | AC | 449 ms
58,836 KB |
testcase_29 | AC | 1,080 ms
69,488 KB |
testcase_30 | AC | 956 ms
69,572 KB |
testcase_31 | AC | 1,075 ms
69,472 KB |
testcase_32 | AC | 965 ms
69,692 KB |
testcase_33 | AC | 941 ms
69,700 KB |
testcase_34 | AC | 971 ms
69,780 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { 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]); boolean[][] 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'); } } ArrayDeque<Integer> deq = new ArrayDeque<>(); int count = 0; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { if (field[i][j]) { count++; deq.add(i * (w + 2) + j); while (deq.size() > 0) { int x = deq.poll(); int xh = x / (w + 2); int xw = x % (w + 2); if (!field[xh][xw]) { continue; } field[xh][xw] = false; if (field[xh][xw + 1]) { deq.add(xh * (w + 2) + xw + 1); } if (field[xh][xw - 1]) { deq.add(xh * (w + 2) + xw - 1); } if (field[xh + 1][xw]) { deq.add((xh + 1) * (w + 2) + xw); } if (field[xh - 1][xw]) { deq.add((xh - 1) * (w + 2) + xw); } } } } } System.out.println(count); } }