#include <bits/stdc++.h>
using namespace std;
#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) x = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
int n, m;
vector<vi> cols;
int ans;
int sum(int c, int t, int b) {
return cols[b][c] - cols[t - 1][c];
}
int main() {
scanf("%d%d", &n, &m);
vi vect;
REP (i, 0, m + 1) vect.pb(0);
cols.pb(vect);
REP (i, 1, n + 1) {
vi vect;
vect.pb(0);
REP (j, 1, m + 1) {
int temp; scanf("%d", &temp);
vect.pb(temp);
ans += temp;
}
cols.pb(vect);
}
REP (i, 1, n + 1) {
REP (j, 1, m + 1) {
cols[i][j] += cols[i - 1][j];
}
}
vector<vector<int>> dp(n + 5, vector<int>(n + 5, 0));
int sub = INF;
REP (k, 1, m + 1) {
REP (i, 1, n + 1) {
REP (j, i, n + 1) {
dp[i][j] = min(dp[i][j], 0) - 2 * sum(k, i, j) + (j - i + 1);
mnto(sub, dp[i][j]);
}
}
}
ans += sub;
printf("%d\n", ans);
return 0;
}
Compilation message
orchard.cpp: In function 'int main()':
orchard.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
35 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
orchard.cpp:43:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
43 | int temp; scanf("%d", &temp);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
18000 KB |
Output is correct |
2 |
Correct |
117 ms |
17936 KB |
Output is correct |
3 |
Correct |
148 ms |
17956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
2756 KB |
Output is correct |
2 |
Correct |
23 ms |
2736 KB |
Output is correct |
3 |
Correct |
23 ms |
2804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
7 ms |
460 KB |
Output is correct |
3 |
Correct |
7 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
4840 KB |
Output is correct |
2 |
Correct |
228 ms |
4856 KB |
Output is correct |
3 |
Correct |
275 ms |
4840 KB |
Output is correct |