# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
120533 |
2019-06-24T18:42:16 Z |
zeyad49 |
Orchard (NOI14_orchard) |
Java 11 |
|
588 ms |
69980 KB |
import java.io.*;
import java.util.*;
public class orchard {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner();
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt(), m = sc.nextInt();
int[][] a = new int[n][m], prefix = new int[n][m];
int ones = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
a[i][j] = sc.nextInt();
if (a[i][j] == 0)
a[i][j] = -1;
else
ones++;
prefix[i][j] = a[i][j];
if (i > 0)
prefix[i][j] += prefix[i - 1][j];
if (j > 0)
prefix[i][j] += prefix[i][j - 1];
if (i > 0 && j > 0)
prefix[i][j] -= prefix[i - 1][j - 1];
}
int ans = 0;
for (int u = 0; u < n; u++) {
for (int d = u; d < n; d++) {
int min = 0;
for (int j = 0; j < m; j++) {
int sum = prefix[d][j];
if (u > 0) {
sum -= prefix[u - 1][j];
}
ans = Math.max(sum - min, ans);
min = Math.min(min, sum);
}
}
}
out.println(ones - ans);
out.close();
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
Scanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
Scanner(String fileName) throws FileNotFoundException {
br = new BufferedReader(new FileReader(fileName));
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
String nextLine() throws IOException {
return br.readLine();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(next());
}
double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(next());
}
boolean ready() throws IOException {
return br.ready();
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
9660 KB |
Output is correct |
2 |
Correct |
78 ms |
9656 KB |
Output is correct |
3 |
Correct |
79 ms |
9720 KB |
Output is correct |
4 |
Correct |
75 ms |
9696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
108 ms |
11876 KB |
Output is correct |
2 |
Correct |
109 ms |
11484 KB |
Output is correct |
3 |
Correct |
121 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
349 ms |
64648 KB |
Output is correct |
2 |
Correct |
373 ms |
63980 KB |
Output is correct |
3 |
Correct |
409 ms |
69980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
27548 KB |
Output is correct |
2 |
Correct |
262 ms |
27252 KB |
Output is correct |
3 |
Correct |
239 ms |
26984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
11968 KB |
Output is correct |
2 |
Correct |
199 ms |
14944 KB |
Output is correct |
3 |
Correct |
186 ms |
14944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
576 ms |
56548 KB |
Output is correct |
2 |
Correct |
588 ms |
56488 KB |
Output is correct |
3 |
Correct |
570 ms |
56100 KB |
Output is correct |