# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
516347 | 2022-01-21T07:37:03 Z | Jomnoi | Orchard (NOI14_orchard) | C++17 | 331 ms | 8496 KB |
#include <bits/stdc++.h> #define DEBUG 0 using namespace std; const int N = 160; const int M = 5e3 + 10; const int INF = 1e9 + 7; int a[N][M]; int dp[M]; int get(int x1, int x2, int y1, int y2) { return a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1] + a[x1 - 1][y1 - 1]; } int main() { int n, m; scanf(" %d %d", &n, &m); int sum = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { scanf(" %d", &a[i][j]); if(a[i][j] == 0) { a[i][j] = 1; } else { sum++; a[i][j] = -1; } a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1]; } } int ans = INF; dp[m + 1] = INF; for(int i = 1; i <= n; i++) { for(int j = i; j <= n; j++) { for(int k = m; k >= 1; k--) { dp[k] = min(dp[k + 1], get(i, j, 1, k)); } if(DEBUG) { cout << "Debugging : " << i << " " << j << endl; for(int k = 1; k <= m; k++) { cout << dp[k] << " "; } cout << endl; } for(int k = 1; k <= m; k++) { ans = min(ans, sum + dp[k] - get(i, j, 1, k - 1)); } } } cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 73 ms | 8496 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 1120 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 768 KB | Output is correct |
2 | Correct | 10 ms | 972 KB | Output is correct |
3 | Correct | 11 ms | 1036 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 320 ms | 4712 KB | Output is correct |
2 | Correct | 331 ms | 4712 KB | Output is correct |
3 | Correct | 325 ms | 4752 KB | Output is correct |