結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
|
| 提出日時 | 2018-06-23 02:05:26 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 792 bytes |
| コンパイル時間 | 5,202 ms |
| コンパイル使用メモリ | 77,212 KB |
| 実行使用メモリ | 832,392 KB |
| 最終ジャッジ日時 | 2024-11-25 13:46:46 |
| 合計ジャッジ時間 | 42,628 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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){
if(a[y][x] == 1){
search(y, x);
}
}
}
}
}