#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
const int mod = 1e9+7;
#define deb(x) cout<<#x<<": "<<x<<endl
int iceil(int a, int b) {
return (a + b - 1) / b;
}
int mul(int a, int b) {
return a * 1ll * b % mod;
}
int binpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(20);
#ifdef strawberryshaker2005
freopen("input.txt", "r", stdin);
#endif
int n,m;
cin>>n>>m;
int grid[n+1][m+1];memset(grid,0,sizeof(grid));
int total=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
int temp;
cin>>temp;
total+=temp;
if(temp==0) temp=-1;
grid[i][j]=grid[i-1][j]+temp;
}
}
int cur=0,sum=0;
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
cur=0;
for(int k=1;k<=m;k++){
cur+=grid[j][k]-grid[i-1][k];
sum=max(sum,cur);
if(cur<0) cur=0;
}
}
}
cout<<total-sum;
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
17856 KB |
Output is correct |
2 |
Correct |
78 ms |
17856 KB |
Output is correct |
3 |
Correct |
95 ms |
17860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3032 KB |
Output is correct |
2 |
Correct |
18 ms |
3032 KB |
Output is correct |
3 |
Correct |
16 ms |
3032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
460 KB |
Output is correct |
3 |
Correct |
5 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
7748 KB |
Output is correct |
2 |
Correct |
161 ms |
7672 KB |
Output is correct |
3 |
Correct |
160 ms |
7676 KB |
Output is correct |