1
+ import java .io .BufferedReader ;
2
+ import java .io .InputStreamReader ;
3
+ import java .util .StringTokenizer ;
4
+
5
+ public class Main {
6
+
7
+ static int n , m ;
8
+ // 도형을 회전, 반전으로 만들 수 있는 모든 경우를 저장
9
+ static int [][][] shapes = { { { 0 , 0 }, { 0 , 1 }, { 0 , 2 }, { 0 , 3 } }, { { 0 , 0 }, { 1 , 0 }, { 2 , 0 }, { 3 , 0 } },
10
+ { { 0 , 0 }, { 1 , 0 }, { 0 , 1 }, { 1 , 1 } }, { { 0 , 0 }, { 1 , 0 }, { 2 , 0 }, { 2 , 1 } },
11
+ { { 0 , 0 }, { 0 , 1 }, { 0 , 2 }, { -1 , 2 } }, { { 0 , 0 }, { 0 , 1 }, { 1 , 1 }, { 2 , 1 } },
12
+ { { 0 , 0 }, { 1 , 0 }, { 0 , 1 }, { 0 , 2 } }, { { 0 , 0 }, { 1 , 0 }, { 2 , 0 }, { 2 , -1 } },
13
+ { { 0 , 0 }, { 0 , 1 }, { 0 , 2 }, { 1 , 2 } }, { { 0 , 0 }, { 0 , 1 }, { 1 , 0 }, { 2 , 0 } },
14
+ { { 0 , 0 }, { 1 , 0 }, { 1 , 1 }, { 1 , 2 } }, { { 0 , 0 }, { 1 , 0 }, { 1 , 1 }, { 2 , 1 } },
15
+ { { 0 , 0 }, { 0 , 1 }, { -1 , 1 }, { -1 , 2 } }, { { 0 , 0 }, { 1 , 0 }, { 1 , -1 }, { 2 , -1 } },
16
+ { { 0 , 0 }, { 0 , 1 }, { 1 , 1 }, { 1 , 2 } }, { { 0 , 0 }, { 1 , 0 }, { 1 , 1 }, { 2 , 0 } },
17
+ { { 0 , 0 }, { 0 , 1 }, { -1 , 1 }, { 0 , 2 } }, { { 0 , 0 }, { 1 , 0 }, { 1 , -1 }, { 2 , 0 } },
18
+ { { 0 , 0 }, { 0 , 1 }, { 0 , 2 }, { 1 , 1 } } };
19
+
20
+ public static void main (String [] args ) throws Exception {
21
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
22
+ StringTokenizer st = new StringTokenizer (br .readLine ());
23
+ n = Integer .parseInt (st .nextToken ());
24
+ m = Integer .parseInt (st .nextToken ());
25
+ int [][] board = new int [n ][m ];
26
+ for (int i = 0 ; i < n ; i ++) {
27
+ st = new StringTokenizer (br .readLine ());
28
+ for (int j = 0 ; j < m ; j ++)
29
+ board [i ][j ] = Integer .parseInt (st .nextToken ());
30
+ }
31
+ int max = 0 ;
32
+ for (int i = 0 ; i < n ; i ++) {
33
+ for (int j = 0 ; j < m ; j ++) {
34
+ // 모든 지점에 대해서 모든 도형을 만들어서 합을 구해줌
35
+ for (int [][] shape : shapes ) {
36
+ int sum = 0 ;
37
+ for (int k = 0 ; k < 4 ; k ++) {
38
+ int y = i + shape [k ][0 ];
39
+ int x = j + shape [k ][1 ];
40
+ if (isValid (y , x ))
41
+ sum += board [y ][x ];
42
+ }
43
+ max = Math .max (max , sum );
44
+ }
45
+ }
46
+ }
47
+ System .out .println (max );
48
+ }
49
+
50
+ // 경계 체크
51
+ private static boolean isValid (int y , int x ) {
52
+ return 0 <= y && y < n && 0 <= x && x < m ;
53
+ }
54
+ }
0 commit comments