Created
July 26, 2023 14:10
-
-
Save youngvctr/9863a4ade968fdcb3ceb37429c62ef91 to your computer and use it in GitHub Desktop.
BOJ | DP[16507] > 어두운 건 무서워
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.StringTokenizer; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
StringTokenizer st = new StringTokenizer(br.readLine()); | |
int R = Integer.parseInt(st.nextToken()); | |
int C = Integer.parseInt(st.nextToken()); | |
int Q = Integer.parseInt(st.nextToken()); | |
int[][] matrix = new int[R + 1][C + 1]; | |
for (int i = 1; i < R + 1; i++) { | |
st = new StringTokenizer(br.readLine()); | |
for (int j = 1; j < C + 1; j++) { | |
matrix[i][j] = matrix[i - 1][j] + matrix[i][j - 1] - matrix[i - 1][j - 1] + Integer.parseInt(st.nextToken()); | |
} | |
} | |
StringBuffer sb = new StringBuffer(); | |
for (int i = 0; i < Q; i++) { | |
st = new StringTokenizer(br.readLine()); | |
int r1 = Integer.parseInt(st.nextToken()); | |
int c1 = Integer.parseInt(st.nextToken()); | |
int r2 = Integer.parseInt(st.nextToken()); | |
int c2 = Integer.parseInt(st.nextToken()); | |
int elCnt = (r2 - r1 + 1) * (c2 - c1 + 1); | |
sb.append((matrix[r2][c2] - matrix[r1-1][c2] - matrix[r2][c1-1] + matrix[r1 - 1][c1 - 1]) / elCnt).append("\n"); | |
} | |
System.out.print(new String(sb)); | |
sb.setLength(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment