티스토리 뷰

백준

백준 소스코드 [C++] 14500 테트로미노

Hani_Levenshtein 2021. 2. 2. 08:13

www.acmicpc.net/problem/14500

 

14500번: 테트로미노

폴리오미노란 크기가 1×1인 정사각형을 여러 개 이어서 붙인 도형이며, 다음과 같은 조건을 만족해야 한다. 정사각형은 서로 겹치면 안 된다. 도형은 모두 연결되어 있어야 한다. 정사각형의 변

www.acmicpc.net

백준 소스코드 [C++] 14500 테트로미노

#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
typedef long long ll;
using namespace std;

int arr[506][506];
int block[19][4][2] = {
	//ㅡ
	{{0, 0}, {0, 1}, {0, 2}, {0, 3}},
	{{0, 0}, {1, 0}, {2, 0}, {3, 0}},

	//ㅁ
	{{0, 0}, {0, 1}, {1, 0}, {1, 1}},

	//ㄴ
	{{0, 0}, {1, 0}, {2, 0}, {2, 1}},
	{{0, 0}, {1, 0}, {2, 0}, {2, -1}},
	{{0, 0}, {1, 0}, {0, 1}, {0, 2}},
	{{0, 0}, {0, 1}, {0, 2}, {-1, 2}},
	{{0, 0}, {1, 0}, {2, 0}, {0, 1}},
	{{0, 0}, {0, 1}, {0, 2}, {1, 2}},
	{{0, 0}, {1, 0}, {1, 1}, {1, 2}},
	{{0, 0}, {0, 1}, {1, 1}, {2, 1}},

	//ㄹ
	{{0, 0}, {1, 0}, {1, 1}, {2, 1}},
	{{0, 0}, {0, 1}, {-1, 1}, {-1, 2}},
	{{0, 0}, {1, 0}, {0, 1}, {-1, 1}},
	{{0, 0}, {0, 1}, {1, 1}, {1, 2}},

	//ㅗ
	{{0, 0}, {0, 1}, {0, 2}, {1, 1}},
	{{0, 0}, {0, 1}, {1, 1}, {-1, 1}},
	{{0, 0}, {0, 1}, {0, 2}, {-1, 1}},
	{{0, 0}, {1, 0}, {2, 0}, {1, 1}},
};


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;

	for (int y = 3; y < n+3; y++) {
		for (int x = 3; x < m+3; x++) {
			cin >> arr[y][x];
		}
	}

	int res = 0;
	for (int i = 0; i < 19; i++)
		for (int y = 3; y < n+3; y++) 
			for (int x = 3; x < m+3; x++) {
				int sum = 0;
				for (int t = 0; t < 4; t++) {
					int ny = y + block[i][t][0];
					int nx = x + block[i][t][1];
					sum += arr[ny][nx];
				}
				res = max(res, sum);
			}

	cout << res << endl;

	return 0;
}
댓글