-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswea2001.java
More file actions
76 lines (51 loc) · 1.62 KB
/
Copy pathswea2001.java
File metadata and controls
76 lines (51 loc) · 1.62 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
67
68
69
70
71
72
73
74
75
76
package java_swea;
import java.util.*;
import java.io.*;
class KillFly {
static int M;
static int[][] sumArr;
static int[][] flyArr;
static void initSumArr(int N) {
// sumArr[0][i], sumArr[i][0] 구하기
for(int i = 1; i<=N; i++) {
for(int j = 1; j<=N; j++) {
sumArr[i][j] = sumArr[i-1][j] + sumArr[i][j-1] - sumArr[i-1][j-1] + flyArr[i][j];
}
}
}
static int maxSum(int n) {
int max = -1;
for(int i = n; i < sumArr.length; i++) {
for(int j = n; j<sumArr.length; j++) {
int sumVal = sumArr[i][j] - sumArr[i-n][j] - sumArr[i][j-n] + sumArr[i-n][j-n];
if (sumVal > max) {
max = sumVal;
}
}
}
return max;
}
}
public class swea2001 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
for(int test_case = 1; test_case <= t; test_case ++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
KillFly.flyArr = new int[N+1][N+1];
KillFly.sumArr = new int[N+1][N+1];
for(int i = 1; i<=N; i++) {
st = new StringTokenizer(br.readLine());
for(int j = 1; j<=N; j++) {
KillFly.flyArr[i][j] = Integer.parseInt(st.nextToken());
}
}
KillFly.initSumArr(N);
sb.append("#"+test_case + " " + KillFly.maxSum(K) + "\n");
}
System.out.println(sb.toString());
}
}