백준공부/java
[백준] 14500번 테트로미노 (gold 4
gomduri43
2023. 7. 12. 14:20
import java.io.*;
import java.util.*;
public class Main{
static ArrayList<int[]> arr=new ArrayList<>();
public static void main(String[] args )throws IOException{
int[] num;
arr.add( num=new int[] {0,0,0,1,1,0,1,1});
arr.add( num=new int[] {0,0,1,0,2,0,3,0});
arr.add( num=new int[] {0,0,0,1,1,1,1,2});
arr.add( num=new int[] {0,0,1,0,2,0,1,1});
arr.add( num=new int[] {0,0,0,1,0,2,1,2});
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st=new StringTokenizer(br.readLine());
int n=Integer.parseInt(st.nextToken());
int m=Integer.parseInt(st.nextToken());
int[][] map=new int[n+1][m+1];
for(int i=1; i<=n; i++){
st=new StringTokenizer(br.readLine());
for(int j=1; j<=m; j++){
map[i][j]=Integer.parseInt(st.nextToken());
}
}
for(int i=1; i<5; i++){
int[] temp=arr.get(i);
//90도 회전
arr.add(num=new int[] {temp[0],temp[1],temp[3],-temp[2],temp[5],-temp[4],temp[7],-temp[6]});
//180도 회전
arr.add(num=new int[] {temp[0],temp[1],-temp[2],-temp[3],-temp[4],-temp[5],-temp[6],-temp[7]});
//270도 회전
arr.add(num=new int[] {temp[0],temp[1],-temp[3],temp[2],-temp[5],temp[4],-temp[7],temp[6]});
//원상태서 상하반전
arr.add(num=new int[] {temp[0],temp[1],temp[2],-temp[3],temp[4],-temp[5],temp[6],-temp[7]});
//원상태에서 좌우반전
arr.add(num=new int[] {temp[0],temp[1],-temp[2],temp[3],-temp[4],temp[5],-temp[6],temp[7]});
//90도 회전에서 좌우반전
arr.add(num=new int[] {temp[0],temp[1],-temp[3],-temp[2],-temp[5],-temp[4],-temp[7],-temp[6]});
//90도 회전에서 상하반전
arr.add(num=new int[] {temp[0],temp[1],temp[3],temp[2],temp[5],temp[4],temp[7],temp[6]});
}
int max=0;
int depth=0;
boolean right=true;
int tempx;
int tempy;
//최댓값 구하기
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
for(int shape=0; shape<arr.size(); shape++ ){
num=arr.get(shape);
right=true;
depth=0;
for(int index=0; index<=6; index+=2 ){
tempx=j+num[index];
tempy=i+num[index+1];
if(tempx<1 || tempy<1 || tempx>m || tempy>n){
right=false;
break;
}
depth+=map[tempy][tempx];
}
if(right){
max= max > depth ? max :depth;
}
}
}
}
bw.write(max+"");
bw.flush();
}
}