#include <bits/stdc++.h>
#define FOR(x, a, b) for (int x = a; x <= b; ++x)
#define FOD(x, a, b) for (int x = a; x >= b; --x)
#define REP(x, a, b) for (int x = a; x < b; ++x)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A, n) { cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl; }
#define PR0(A, n) { cout << #A << " = "; REP(_, 0, n) cout << A[_] << " "; cout << endl; }
using namespace std;
typedef long long LL;
typedef pair <int, int> II;
const int INF = 0x3f3f3f3f;
int n, m;
vector <vector <int> > s[2];
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
scanf("%d%d", &n, &m);
REP(i, 0, 2) {
s[i].resize(n + 2, vector <int> (m + 2, 0));
}
int all = 0;
FOR(i, 1, n) {
FOR(j, 1, m) {
int v; scanf("%d", &v);
all += (v == 1);
FOR(k, 0, 1) s[k][i][j] = s[k][i - 1][j];
s[v][i][j]++;
}
}
int ans = INF;
FOR(i, 1, n) {
FOR(j, i, n) {
int prev = 0, sum = 0;
FOR(k, 1, m) {
int diff = (s[0][j][k] - s[0][i - 1][k]) - (s[1][j][k] - s[1][i - 1][k]);
sum += diff;
ans = min(ans, sum - prev);
prev = max(prev, sum);
}
}
}
// DEBUG(ans);
cout << all + ans << endl;
return 0;
}
Compilation message
orchard.cpp: In function 'int main()':
orchard.cpp:26:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
orchard.cpp:33:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int v; scanf("%d", &v);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
1 ms |
508 KB |
Output is correct |
4 |
Correct |
2 ms |
584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
912 KB |
Output is correct |
2 |
Correct |
5 ms |
928 KB |
Output is correct |
3 |
Correct |
3 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
30140 KB |
Output is correct |
2 |
Correct |
131 ms |
32076 KB |
Output is correct |
3 |
Correct |
134 ms |
34100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
34100 KB |
Output is correct |
2 |
Correct |
27 ms |
34100 KB |
Output is correct |
3 |
Correct |
26 ms |
34100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
34100 KB |
Output is correct |
2 |
Correct |
8 ms |
34100 KB |
Output is correct |
3 |
Correct |
7 ms |
34100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
34100 KB |
Output is correct |
2 |
Correct |
197 ms |
34100 KB |
Output is correct |
3 |
Correct |
199 ms |
34100 KB |
Output is correct |