[JOI合宿]2007-Day1:Mall [JOI関連]
二次元の累積和を取る問題でした.
-1の土地は10^8で初期化しておきました.
実装 10 分 + Debug 0 分 (1発AC)
-1の土地は10^8で初期化しておきました.
実装 10 分 + Debug 0 分 (1発AC)
#include <stdio.h> #include <limits.h> typedef long long ll; ll map[1024][1024]; int main(void) { int x, y; int i, j; int a, b; ll ans; scanf("%d%d", &x, &y); scanf("%d%d", &a, &b); for (i = 0; i < y; i++){ for (j = 0; j < x; j++){ scanf("%lld", &map[i][j]); if (map[i][j] == -1){ map[i][j] = 100000000; } if (i > 0){ map[i][j] += map[i - 1][j]; } if (j > 0){ map[i][j] += map[i][j - 1]; } if (i > 0 && j > 0){ map[i][j] -= map[i - 1][j - 1]; } } } ans = INT_MAX; for (i = b - 1; i < y; i++){ for (j = a - 1; j < x; j++){ ll temp; temp = map[i][j]; if (i >= b){ temp -= map[i - b][j]; } if (j >= a){ temp -= map[i][j - a]; } if (i >= b && j >= a){ temp += map[i - b][j - a]; } ans = ans > temp ? temp : ans; } } printf("%lld\n", ans); return (0); }
2012-05-30 22:30
nice!(0)
コメント(0)
トラックバック(0)
コメント 0