-
Notifications
You must be signed in to change notification settings - Fork 0
/
4920.java
95 lines (74 loc) · 2.46 KB
/
4920.java
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import org.w3c.dom.Node;
import java.io.*;
import java.util.*;
public class Main {
static int[][] row = {{0, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 1}, {0, 1, 0}};
static int[][] col = {{1, 1, 1}, {1, 0, 1}, {1, 1, 0}, {1, 1, -1}, {1, 0, -1}};
static int[][] board;
static int N;
static int max;
static int test = 1;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
while (true) {
st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
if (N == 0) {
break;
}
board = new int[N][N];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < N; j++) {
board[i][j] = Integer.parseInt(st.nextToken());
}
}
max = Integer.MIN_VALUE;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
solve(i, j);
}
}
bw.write(test++ + ". " + max + "\n");
}
bw.flush();
}
public static void solve(int x, int y) {
for (int i = 0; i < row.length; i++) {
int type = 0;
while (type++ < 4) {
int sum = board[x][y];
boolean flag = false;
rotate(i);
int nx = x;
int ny = y;
for (int j = 0; j < row[i].length; j++) {
nx += row[i][j];
ny += col[i][j];
if (0 <= nx && nx < N && 0 <= ny && ny < N) {
sum += board[nx][ny];
} else {
flag = true;
break;
}
}
if (flag) {
continue;
}
if (max < sum) {
max = sum;
}
}
}
}
public static void rotate(int index) {
for (int i = 0; i < row[index].length; i++) {
int tempRow = row[index][i];
int tempCol = col[index][i];
row[index][i] = tempCol;
col[index][i] = -tempRow;
}
}
}