4중 for문을 이용해서 풀이하면 RunTime Error 가 난다.
구글링해보니 대부분 이방법으로 풀었는데 어떻게 넘어간건지 모르겠다. DP 방법을 사용해서 풀수 있다던데 잘 이해가 안되서 아직 해결하지 못했다. 나중에 따로 공부 해서 올릴것.
[RunTime Error]
class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int T; T=sc.nextInt(); for(int test_case = 1; test_case <= T; test_case++) { int N = sc.nextInt(); int M = sc.nextInt(); int[][] map = new int[N][N]; int max = 0; for(int i = 0; i<N; i++){ for(int j = 0; i <N; j++){ map[i][j]= sc.nextInt(); } } for(int i = 0; i<= N-M; i++){ for(int j = 0; j <= N-M; j++){ int sum = 0; for(int x = i; x < i+M; x++){ for(int y =i; y < j+M; y++){ sum += map[x][y]; } } if(max < sum) max = sum; } } System.out.println("#"+test_case + " " + max) ;
}
}
}