[BOJ 14500] 테트로미노
출처 : https://www.acmicpc.net/problem/14500
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX_N 512
int N, M, result;
int map[MAX_N][MAX_N];
int cc[19][4][2] = {
{ { 0,0 },{ 1,0 },{ 0,1 },{ 1,1 } },
{ { 0,0 },{ 0,1 },{ 0,2 },{ 0,3 } },
{ { 0,0 },{ 1,0 },{ 2,0 },{ 3,0 } },
{ { 0,0 },{ 1,0 },{ 1,1 },{ 2,1 } },
{ { 0,0 },{ 0,1 },{ 1,1 },{ 1,2 } },
{ { 1,0 },{ 1,1 },{ 0,1 },{ 0,2 } },
{ { 0,1 },{ 1,1 },{ 1,0 },{ 2,0 } },
{ { 0,1 },{ 1,0 },{ 1,1 },{ 1,2 } },
{ { 0,0 },{ 0,1 },{ 0,2 },{ 1,1 } },
{ { 0,1 },{ 1,0 },{ 1,1 },{ 2,1 } },
{ { 0,0 },{ 1,0 },{ 1,1 },{ 2,0 } },
{ { 0,0 },{ 0,1 },{ 0,2 },{ 1,2 } },
{ { 0,1 },{ 1,1 },{ 2,1 },{ 2,0 } },
{ { 1,0 },{ 1,1 },{ 1,2 },{ 0,2 } },
{ { 0,0 },{ 0,1 },{ 1,0 },{ 2,0 } },
{ { 0,0 },{ 0,1 },{ 0,2 },{ 1,0 } },
{ { 0,0 },{ 1,0 },{ 2,0 },{ 2,1 } },
{ { 0,0 },{ 1,0 },{ 1,1 },{ 1,2 } },
{ { 0,0 },{ 0,1 },{ 1,1 },{ 2,1 } },
};
int main()
{
cin >> N >> M; result = 0;
for (int i = 0; i < N; i++)for (int j = 0;j < M;j++) map[i][j] = 0;
for (int i = 1+5; i <= N+5; i++)for (int j = 1+5;j <= M+5;j++) cin >> map[i][j];
for (int i = 1+5; i <= N+5; i++)for (int j = 1+5;j <= M+5;j++)
{
for (int b = 0; b < 19; b++)
{
int res = 0;
for (int c = 0;c < 4;c++)
{
int r = i + cc[b][c][0]; int rr = j + cc[b][c][1];
res += map[r][rr];
}
result = max(result, res);
}
}
cout << result;
}