Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.067 s | 10 KBi |
#2 |
Correcto
|
0.077 s | 10 KBi |
#3 |
Incorrecto
|
0.072 s | 13 KBi |
#4 |
Correcto
|
0.06 s | 18 KBi |
#5 |
Correcto
|
0.076 s | 11 KBi |
#6 |
Correcto
|
0.069 s | 35 KBi |
#7 |
Correcto
|
0.064 s | 10 KBi |
#8 |
Incorrecto
|
0.137 s | 11 KBi |
#9 |
Correcto
|
0.123 s | 37 KBi |
#10 |
Correcto
|
0.104 s | 13 KBi |
#11 |
Correcto
|
0.11 s | 20 KBi |
#12 |
Correcto
|
0.111 s | 11 KBi |
#13 |
Correcto
|
0.108 s | 11 KBi |
#14 |
Correcto
|
0.141 s | 11 KBi |
#15 |
Correcto
|
0.112 s | 11 KBi |
#16 |
Correcto
|
0.129 s | 11 KBi |
#17 |
Correcto
|
0.134 s | 13 KBi |
#18 |
Correcto
|
0.133 s | 11 KBi |
import java.io.InputStreamReader; import java.io.IOException; import java.io.DataInputStream; import java.io.FileInputStream; import java.lang.Math; public class Main{ static class Reader{ final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader(){ din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException{ din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException{ byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) break; else continue; } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException{ int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } private void fillBuffer() throws IOException{ bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException{ if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException{ if (din == null) return; din.close(); } } public static void updateMatrix(int[][] matrix){ int N = matrix.length; int M = matrix[0].length; for(int r = 1; r < N; r++) matrix[r][0] += matrix[r - 1][0]; for(int c = 1; c < M; c++) matrix[0][c] += matrix[0][c - 1]; for(int r = 1; r < N; r++) for(int c = 1; c < M; c++){ matrix[r][c] += matrix[r - 1][c]; matrix[r][c] += matrix[r][c - 1]; matrix[r][c] -= matrix[r - 1][c - 1]; } } public static int querySubmatrixSum(int[][] matrix, int r1, int c1, int r2, int c2){ if(r1 == c1 && c1 == 0) return matrix[r2][c2]; if(r1 == 0) return matrix[r2][c2] - matrix[r2][c1 - 1]; if(c1 == 0) return matrix[r2][c2] - matrix[r1 - 1][c2]; return matrix[r2][c2] - matrix[r1 - 1][c2] - matrix[r2][c1 - 1] + matrix[r1 - 1][c1 - 1]; } public static void main(String[] args) throws IOException { Reader fr = new Reader(); int N = fr.nextInt(); int M = fr.nextInt(); int[][] matrix = new int[N][M]; int res = 0; for(int r = 0; r < N; r++) for(int c = 0; c < M; c++) matrix[r][c] = fr.nextInt(); updateMatrix(matrix); for(int r = 0; r < N; r++) for(int c = 0; c < M; c++) for(int rr = r; rr < N; rr++) for(int cc = c; cc < M; cc++) res = Math.max(res, querySubmatrixSum(matrix, r, c, rr, cc)); System.out.println(res); } }