SWEA_2001) 파리 퇴치
SWEA
# D2
2001) 파리 퇴치 (19.10.04)
문제 링크 (SW Expert Academy)
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
|
import java.io.*;
import java.util.*;
public class Solution {
public static int[][] map;
public static ArrayList<Integer> list;
public static void cal(int n, int m, int p, int q) {
int sum = 0;
for(int i=p;i<p+m;i++) {
for(int j=q; j<q+m;j++) {
sum = sum+map[i][j];
}
}
list.add(sum);
}
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 tk;
int t = Integer.parseInt(br.readLine());
for(int i=1;i<=t;i++) {
tk = new StringTokenizer(br.readLine());
int n = Integer.parseInt(tk.nextToken());
int m = Integer.parseInt(tk.nextToken());
map = new int[n][n];
for(int p=0;p<n;p++) {
tk = new StringTokenizer(br.readLine());
for(int q=0;q<n;q++) {
map[p][q] = Integer.parseInt(tk.nextToken());
}
}
list = new ArrayList<Integer>();
for(int p=0;p<=n-m;p++) {
for(int q=0;q<=n-m;q++) {
cal(n, m ,p, q);
}
}
int max = 0;
for(int k:list) {
max = Math.max(max, k);
}
bw.write("#" + i + " " + max + "\n");
}
bw.flush();
bw.close();
}
}
| cs |
댓글
댓글 쓰기