# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
10695 |
2014-11-07T12:10:33 Z |
gs14004 |
Orchard (NOI14_orchard) |
C++ |
|
300 ms |
16756 KB |
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int n,m,fcnt;
int* a[155];
int* s[155];
int ca[10005];
int sum(){
// int me = *max_element(ca+1,ca+m+1);
// if(me < 0) return -me;
int mv = 0, c = 0;
for (int j=1; j<=m; j++) {
c += ca[j];
if(c < 0) c = 0;
mv = max(mv,c);
}
return -mv;
}
int calc(int x, int y){
int hi = y - x + 1;
for (int j=1; j<=m; j++) {
ca[j] = 2 * (s[y][j] - s[y][j-1] - s[x-1][j] + s[x-1][j-1]) - hi;
}
return fcnt + sum();
}
int main(){
scanf("%d %d",&n,&m);
for (int i=0; i<=n; i++) {
a[i] = (int*)malloc(sizeof(int) * (m + 1));
s[i] = (int*)malloc(sizeof(int) * (m + 1));
}
for (int i=0; i<=m; i++) {
s[0][i] = 0;
}
for (int i=0; i<=n; i++) {
s[i][0] = 0;
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
scanf("%d",&a[i][j]);
s[i][j] = s[i][j-1] + s[i-1][j] - s[i-1][j-1] + a[i][j];
}
}
fcnt = s[n][m];
int res = 1e9;
for (int i=1; i<=n; i++) {
for (int j=i; j<=n; j++) {
res = min(res,calc(i,j));
}
}
printf("%d",res);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1128 KB |
Output is correct |
2 |
Correct |
0 ms |
1128 KB |
Output is correct |
3 |
Correct |
0 ms |
1128 KB |
Output is correct |
4 |
Correct |
0 ms |
1128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
1300 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
104 ms |
16756 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
3476 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1128 KB |
Output is correct |
2 |
Correct |
4 ms |
1260 KB |
Output is correct |
3 |
Correct |
4 ms |
1260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
288 ms |
7012 KB |
Output is correct |
2 |
Correct |
292 ms |
7012 KB |
Output is correct |
3 |
Correct |
300 ms |
7012 KB |
Output is correct |