ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 테트로미노
    백준알고리즘 2019. 7. 21. 03:29
    import java.util.*;
    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int m = sc.nextInt();
            int[][] a = new int[n][m];
            for (int i=0; i<n; i++) {
                for (int j=0; j<m; j++) {
                    a[i][j] = sc.nextInt();
                }
            }
            int ans = 0;
            for (int i=0; i<n; i++) {
                for (int j=0; j<m; j++) {
                    if (j+3 < m) {
                        int temp = a[i][j] + a[i][j+1] + a[i][j+2] + a[i][j+3];
                        if (ans < temp) ans = temp;
                    }
                    if (i+3 < n) {
                        int temp = a[i][j] + a[i+1][j] + a[i+2][j] + a[i+3][j];
                        if (ans < temp) ans = temp;
                    }
                    if (i+1 < n && j+2 < m) {
                        int temp = a[i][j] + a[i+1][j] + a[i+1][j+1] + a[i+1][j+2];
                        if (ans < temp) ans = temp;
                    }
                    if (i+2 < n && j+1 < m) {
                        int temp = a[i][j] + a[i][j+1] + a[i+1][j] + a[i+2][j];
                        if (ans < temp) ans = temp;
                    }
                    if (i+1 < n && j+2 < m) {
                        int temp = a[i][j] + a[i][j+1] + a[i][j+2] + a[i+1][j+2];
                        if (ans < temp) ans = temp;
                    }
                    if (i+2 < n && j-1 >= 0) {
                        int temp = a[i][j] + a[i+1][j] + a[i+2][j] + a[i+2][j-1];
                        if (ans < temp) ans = temp;
                    }
                    if (i-1 >= 0 && j+2 < m) {
                        int temp = a[i][j] + a[i][j+1] + a[i][j+2] + a[i-1][j+2];
                        if (ans < temp) ans = temp;
                    }
                    if (i+2 < n && j+1 < m) {
                        int temp = a[i][j] + a[i+1][j] + a[i+2][j] + a[i+2][j+1];
                        if (ans < temp) ans = temp;
                    }
                    if (i+1 < n && j+2 < m) {
                        int temp = a[i][j] + a[i][j+1] + a[i][j+2] + a[i+1][j];
                        if (ans < temp) ans = temp;
                    }
                    if (i+2 < n && j+1 < m) {
                        int temp = a[i][j] + a[i][j+1] + a[i+1][j+1] + a[i+2][j+1];
                        if (ans < temp) ans = temp;
                    }
                    if (i+1 < n && j+1 < m) {
                        int temp = a[i][j] + a[i][j+1] + a[i+1][j] + a[i+1][j+1];
                        if (ans < temp) ans = temp;
                    }
                    if (i-1 >= 0 && j+2 < m) {
                        int temp = a[i][j] + a[i][j+1] + a[i-1][j+1] + a[i-1][j+2];
                        if (ans < temp) ans = temp;
                    }
                    if (i+2 < n && j+1 < m) {
                        int temp = a[i][j] + a[i+1][j] + a[i+1][j+1] + a[i+2][j+1];
                        if (ans < temp) ans = temp;
                    }
                    if (i+1 < n && j+2 < m) {
                        int temp = a[i][j] + a[i][j+1] + a[i+1][j+1] + a[i+1][j+2];
                        if (ans < temp) ans = temp;
                    }
                    if (i+2 < n && j-1 >= 0) {
                        int temp = a[i][j] + a[i+1][j] + a[i+1][j-1] + a[i+2][j-1];
                        if (ans < temp) ans = temp;
                    }
                    if (j+2 < m) {
                        int temp = a[i][j] + a[i][j+1] + a[i][j+2];
                        if (i-1 >= 0) {
                            int temp2 = temp + a[i-1][j+1];
                            if (ans < temp2) ans = temp2;
                        }
                        if (i+1 < n) {
                            int temp2 = temp + a[i+1][j+1];
                            if (ans < temp2) ans = temp2;
                        }
                    }
                    if (i+2 < n) {
                        int temp = a[i][j] + a[i+1][j] + a[i+2][j];
                        if (j+1 < m) {
                            int temp2 = temp + a[i+1][j+1];
                            if (ans < temp2) ans = temp2;
                        }
                        if (j-1 >= 0) {
                            int temp2 = temp + a[i+1][j-1];
                            if (ans < temp2) ans = temp2;
                        }
                    }
                }
            }
            System.out.println(ans);
        }
    }

    브루트포스로풀기.. 그냥 도형만들어서 했어도 좋을듯 자바가 편해서 자바로해보았다

    '백준알고리즘' 카테고리의 다른 글

    리모컨  (0) 2019.07.21
    퇴사  (0) 2019.07.21
    안전영역  (0) 2019.07.20
    인구 이동  (0) 2019.07.17
    영역 구하기  (0) 2019.07.17

    댓글

Designed by Tistory.