16931번: 겉넓이 구하기

📝 Memo


Memory : 2016

Time : 0


🖥️ Code


#include <bits/stdc++.h>

int max(int a, int b)
{
	if (a > b)
		return a;
	return b;
}

int main()
{
	int n, m;
	int map[102][102];
	int count = 0;

	scanf("%d %d",&n,&m);
	for(int i=0;i<102;i++) {
		for(int j=0;j<102;j++)
			map[i][j] = 0;
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=m;j++)
			scanf("%d",&map[i][j]);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			count += 2;
			count += max(map[i][j] - map[i][j-1], 0);
			count += max(map[i][j] - map[i][j+1], 0);
			count += max(map[i][j] - map[i-1][j], 0);
			count += max(map[i][j] - map[i+1][j], 0);
		}
	}
	printf("%d",count);
}