Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

걸음마부터 달리기

[25.03.20] 테트리미노 본문

카테고리 없음

[25.03.20] 테트리미노

성추 2025. 3. 20. 15:57

 

 

테트리미노 점수를 구할때 중심 좌표의 점수를 안더하고 있었음.

시간복잡도 유의 , 노가다 유의

import java.util.*;
import java.lang.*;
import java.io.*;

// The main method must be in a class named "Main".
class Main {
    static Point[][] tet = new Point[19][3];  
    static int[][] score ;
    static int N;
    static int M;
    static int max = Integer.MIN_VALUE;
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        N = Integer.parseInt(s[0]);
        M= Integer.parseInt(s[1]);
        score=new int[N][M];
        for(int i=0; i<N; i++){
            s = br.readLine().split(" ");
            for(int j=0; j<M; j++){
                score[i][j]= Integer.parseInt(s[j]);
            }
        }
        tet[0]=new Point[] {new Point(0,1) ,new Point(0,2) ,new Point(0,3)};
        tet[1]= new Point[] {new Point(-1,0) , new Point(-2,0) , new Point(-3,0)};
        tet[2] = new Point[] {new Point(1,0) , new Point(2,0) , new Point(0,1)};
        tet[3] = new Point[] {new Point(-1,0) , new Point(0,1) , new Point(0,2)};
        tet[4]= new Point[] {new Point(0,1) , new Point(-1,1) , new Point(-2,1)};
        tet[5]= new Point[] {new Point(0,1) , new Point(0,2) , new Point(1,2)};
        tet[6]= new Point[] {new Point(0,1) , new Point(1,1) , new Point(2,1)};
        tet[7]= new Point[] {new Point(-1,0) , new Point(-1,1) , new Point(-1,2)};
        tet[8] = new Point[] {new Point(0,1) , new Point(0,2) , new Point(-1,2)};
        tet[9]= new Point[] {new Point(1,0) , new Point(2,0) , new Point(2,1)};
        tet[10]= new Point[] {new Point(-1,0) , new Point(0,1) , new Point(-1,1)};
        tet[11]= new Point[] {new Point(-1,0) , new Point(-1,1) , new Point(-2,1)};
        tet[12]= new Point[] {new Point(0,1) , new Point(-1,1) , new Point(-1,2)};
        tet[13]= new Point[] {new Point(0,1) , new Point(1,1) , new Point(1,2)};
        tet[14]= new Point[] {new Point(0,-1) , new Point(0,1) , new Point(-1,0)};
        tet[15]=new Point[] {new Point(0,-1) , new Point(1,0) , new Point(0,1)};
        tet[16]= new Point[] {new Point(0,-1) , new Point(1,0) , new Point(-1,0)};
        tet[17]= new Point[] {new Point(1,0) , new Point(-1,0) , new Point(0,1)};
        tet[18] = new Point[] {new Point(-1,0),new Point(0,1),new Point(1,1)};

        for(int i=0; i<N; i++){
            for(int j=0; j<M; j++){
                for(int z=0; z<19; z++){
                    int sum =score[i][j];
                    for(int k=0; k<3; k++){
                        int row = i+tet[z][k].row;
                        int column= j+tet[z][k].column;
                        if( !(row>=0 && row<N && column>=0 && column<M)){
                            break;
                        }
                        else{
                            sum+=score[row][column];
                        }
                    }
                    max=Math.max(sum,max);
                }
            }
        }
        System.out.printf("%d",max);
    }

    static class Point{
        int row;
        int column;

        public Point(int x,int y){
            this.row=x;
            this.column=y;
        }
    }
    
}