結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2018-06-23 02:13:44 |
言語 | Java (openjdk 23) |
結果 |
MLE
|
実行時間 | - |
コード長 | 779 bytes |
コンパイル時間 | 4,912 ms |
コンパイル使用メモリ | 77,488 KB |
実行使用メモリ | 832,860 KB |
最終ジャッジ日時 | 2024-11-25 13:48:33 |
合計ジャッジ時間 | 46,026 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 MLE * 2 |
ソースコード
import java.util.*; public class No697{ static int H, W; static int[][] a; static int[] dx = {0, 1, 0, -1}; static int[] dy = {-1, 0, 1, 0}; public static void main(String[] args){ Scanner sc = new Scanner(System.in); H = sc.nextInt(); W = sc.nextInt(); a = new int[H][W]; for(int h = 0; h < H; h++){ for(int w = 0; w < W; w++){ a[h][w] = sc.nextInt(); } } int ans = 0; for(int h = 0; h < H; h++){ for(int w = 0; w < W; w++){ if(a[h][w] == 1){ search(h, w); ans++; } } } System.out.println(ans); } private static void search(int h, int w){ a[h][w] = 0; for(int i = 0; i < 4; i++){ int x = w+dx[i], y = h+dy[i]; if(x >= 0 && x < W && y >= 0 && y < H && a[y][x] == 1){ search(y, x); } } } }