結果

問題 No.697 池の数はいくつか
ユーザー Daigo HIROOKA
提出日時 2018-06-23 00:51:20
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 702 bytes
コンパイル時間 3,434 ms
コンパイル使用メモリ 77,152 KB
実行使用メモリ 122,500 KB
最終ジャッジ日時 2024-11-25 13:47:39
合計ジャッジ時間 39,400 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class No697{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int W = sc.nextInt();

		int ans = 0;
		int[][] a = new int[H+2][W+2];
		Arrays.fill(a[0], 0);
		Arrays.fill(a[H+1], 0);
		for(int h = 1; h < H+1; h++){
			Arrays.fill(a[h], 0);
			for(int w = 1; w < W+1; w++){
				a[h][w] = sc.nextInt();
				if(a[h][w] == 1 &&
				   (a[h][w-1]==0 && a[h-1][w]==0)){
					ans++;
				}
			}
		}

		for(int h = 2; h < H+1; h++){
			for(int w = 2; w < W+1; w++){
				if(a[h][w] == 1 &&
				   (a[h][w-1]==0 && a[h-1][w]==0 && (a[h][w+1]==1 || a[h+1][w]==1))){
					ans--;
				}
			}
		}
		
		System.out.println(ans);
	}
}
0