-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14500.java
More file actions
66 lines (61 loc) · 2.51 KB
/
Copy path14500.java
File metadata and controls
66 lines (61 loc) · 2.51 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// https://www.acmicpc.net/problem/14500
// 테트로미노
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
static int n, m, map[][];
static int[] stick = {0, 1, 0, 1, 0, 1}, square = {0, 1, 1, 0, 0, -1};
static int[] Lbrick1 = {1, 0, 1, 0, 0, 1}, Lbrick2 = {1, 0, 1, 0, 0, -1};
static int[] spark1 = {1, 0, 0, 1, 1, 0}, spark2 = {1, 0, 0, -1, 1, 0};
static int[] Tbrick = {0, 1, 0, 1, 1, -1};
static int[][] twoRot = {stick, spark1, spark2};
static int[][] fourRot = {Lbrick1, Lbrick2, Tbrick};
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(reader.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
map = new int[n][m];
for(int i=0; i<n; i++){
st = new StringTokenizer(reader.readLine());
for(int j=0; j<m; j++){
map[i][j] = Integer.parseInt(st.nextToken());
}
}
long startTime = System.currentTimeMillis();
int max = 0;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
max = Math.max(max, getVal(i, j, square, 0));
for(int[] block : twoRot){
max = Math.max(max, getVal(i, j, block, 0));
max = Math.max(max, getVal(i, j, block, 1));
}
for(int[] block : fourRot){
max = Math.max(max, getVal(i, j, block, 0));
max = Math.max(max, getVal(i, j, block, 1));
max = Math.max(max, getVal(i, j, block, 2));
max = Math.max(max, getVal(i, j, block, 3));
}
}
}
System.out.println(max);
//System.out.println(System.currentTimeMillis()-startTime+"ms");
}
public static int getVal(int x, int y, int[] block, int rotation){
int idx = 0, val = map[x][y];
for(int i=0; i<3; i++){
switch(rotation){
case 0: x += block[idx++]; y += block[idx++]; break;
case 1: y += block[idx++]; x -= block[idx++]; break;
case 2: x -= block[idx++]; y -= block[idx++]; break;
case 3: y -= block[idx++]; x += block[idx++]; break;
}
if(x < 0 || n <= x || y < 0 || m <= y)
return -1;
val += map[x][y];
}
return val;
}
}