BOJ 14500, 테트로미노
Source: BOJ 14500 테트로미노
#include <bits/stdc++.h>
using namespace std;
int n, m;
int board[510][510];
const char block[19][4][5] = {
{
{"1111"},
{"0000"},
{"0000"},
{"0000"}
},
{
{"1000"},
{"1000"},
{"1000"},
{"1000"}
},
{
{"1000"},
{"1000"},
{"1100"},
{"0000"}
},
{
{"1110"},
{"1000"},
{"0000"},
{"0000"}
},
{
{"1100"},
{"0100"},
{"0100"},
{"0000"}
},
{
{"0010"},
{"1110"},
{"0000"},
{"0000"}
},
{
{"0100"},
{"0100"},
{"1100"},
{"0000"}
},
{
{"1110"},
{"0010"},
{"0000"},
{"0000"}
},
{
{"1100"},
{"1000"},
{"1000"},
{"0000"}
},
{
{"1000"},
{"1110"},
{"0000"},
{"0000"}
},
{
{"1000"},
{"1100"},
{"0100"},
{"0000"}
},
{
{"0110"},
{"1100"},
{"0000"},
{"0000"}
},
{
{"0100"},
{"1100"},
{"1000"},
{"0000"}
},
{
{"1100"},
{"0110"},
{"0000"},
{"0000"}
},
{
{"1110"},
{"0100"},
{"0000"},
{"0000"}
},
{
{"1000"},
{"1100"},
{"1000"},
{"0000"}
},
{
{"0100"},
{"1110"},
{"0000"},
{"0000"}
},
{
{"0100"},
{"1100"},
{"0100"},
{"0000"}
},
{
{"1100"},
{"1100"},
{"0000"},
{"0000"}
}
};
int calc(int a, int b, int k){
int ret = 0;
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
ret += (block[k][i][j] - '0') * board[i+a][j+b];
}
}
return ret;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
cin>>board[i][j];
}
}
for(int i=0; i<n+3; i++){
for(int j=m; j<m+3; j++){
board[i][j] = -100000;
}
}
for(int i=n; i<n+3; i++){
for(int j=0; j<m+3; j++){
board[i][j] = -100000;
}
}
int mx = 0;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
for(int k=0; k<19; k++){
mx = max(mx, calc(i, j, k));
}
}
}
cout<<mx<<'\n';
}
Leave a comment