結果
問題 | No.697 池の数はいくつか |
ユーザー | tenten |
提出日時 | 2020-09-03 11:57:10 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,283 bytes |
コンパイル時間 | 5,625 ms |
コンパイル使用メモリ | 77,620 KB |
実行使用メモリ | 761,176 KB |
最終ジャッジ日時 | 2024-05-04 07:07:19 |
合計ジャッジ時間 | 51,528 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 138 ms
53,916 KB |
testcase_01 | AC | 134 ms
54,376 KB |
testcase_02 | AC | 139 ms
54,172 KB |
testcase_03 | AC | 135 ms
53,844 KB |
testcase_04 | AC | 136 ms
53,860 KB |
testcase_05 | AC | 135 ms
53,928 KB |
testcase_06 | AC | 134 ms
54,196 KB |
testcase_07 | AC | 135 ms
53,924 KB |
testcase_08 | AC | 134 ms
53,808 KB |
testcase_09 | AC | 135 ms
53,760 KB |
testcase_10 | AC | 141 ms
54,276 KB |
testcase_11 | AC | 137 ms
53,820 KB |
testcase_12 | AC | 136 ms
53,880 KB |
testcase_13 | AC | 143 ms
54,096 KB |
testcase_14 | AC | 141 ms
54,156 KB |
testcase_15 | AC | 137 ms
54,148 KB |
testcase_16 | AC | 137 ms
53,852 KB |
testcase_17 | AC | 136 ms
54,024 KB |
testcase_18 | AC | 138 ms
54,000 KB |
testcase_19 | AC | 137 ms
54,380 KB |
testcase_20 | AC | 138 ms
53,708 KB |
testcase_21 | AC | 136 ms
54,272 KB |
testcase_22 | AC | 142 ms
54,308 KB |
testcase_23 | AC | 143 ms
54,068 KB |
testcase_24 | AC | 1,384 ms
71,444 KB |
testcase_25 | AC | 1,362 ms
71,372 KB |
testcase_26 | AC | 1,353 ms
71,160 KB |
testcase_27 | AC | 1,371 ms
71,180 KB |
testcase_28 | AC | 1,372 ms
71,272 KB |
testcase_29 | TLE | - |
testcase_30 | AC | 5,865 ms
90,612 KB |
testcase_31 | TLE | - |
testcase_32 | AC | 5,350 ms
90,668 KB |
testcase_33 | AC | 5,581 ms
90,472 KB |
testcase_34 | AC | 5,501 ms
91,244 KB |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int h = sc.nextInt(); int w = sc.nextInt(); boolean[][] field = new boolean[h + 2][w + 2]; boolean[][] used = new boolean[h + 2][w + 2]; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { field[i][j] = (sc.nextInt() == 1); } } int count = 0; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { if (field[i][j] && !used[i][j]) { count++; setUse(i, j, field, used); } } } System.out.println(count); } static void setUse(int r, int c, boolean[][] field, boolean[][] used) { if (field[r][c] && !used[r][c]) { used[r][c] = true; if (field[r - 1][c] && !used[r - 1][c]) { setUse(r - 1, c, field, used); } if (field[r + 1][c] && !used[r + 1][c]) { setUse(r + 1, c, field, used); } if (field[r][c - 1] && !used[r][c - 1]) { setUse(r, c - 1, field, used); } if (field[r][c + 1] && !used[r][c + 1]) { setUse(r, c + 1, field, used); } } } }