# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
477863 |
2021-10-04T08:50:24 Z |
BThero |
Orchard (NOI14_orchard) |
C++17 |
|
1000 ms |
12164 KB |
#include <bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m, 0));
vector<vector<int>> p(n, vector<int>(m, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
int ans = (int)1e9;
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cnt += a[i][j];
if (a[i][j] == 1) {
a[i][j] = -1;
}
else {
a[i][j] = 1;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
p[i][j] = a[i][j]
+ (i > 0 ? p[i - 1][j] : 0)
+ (j > 0 ? p[i][j - 1] : 0)
- (i > 0 && j > 0 ? p[i - 1][j - 1] : 0);
}
}
for (int x1 = 0; x1 < n; x1++) {
for (int y1 = 0; y1 < m; y1++) {
for (int x2 = x1; x2 < n; x2++) {
for (int y2 = y1; y2 < m; y2++) {
int cur = p[x2][y2]
- (x1 > 0 ? p[x1 - 1][y2] : 0)
- (y1 > 0 ? p[x2][y1 - 1] : 0)
+ (x1 > 0 && y1 > 0 ? p[x1 - 1][y1 - 1] : 0);
ans = min(ans, cnt + cur);
}
}
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 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 |
Correct |
131 ms |
468 KB |
Output is correct |
2 |
Correct |
144 ms |
496 KB |
Output is correct |
3 |
Correct |
135 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1081 ms |
12164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1097 ms |
2244 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
380 KB |
Output is correct |
2 |
Correct |
204 ms |
516 KB |
Output is correct |
3 |
Correct |
220 ms |
524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1097 ms |
6092 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |