fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1005;
  5.  
  6. int n, m, p;
  7. int a[N][N];
  8.  
  9. int pre[N][N];
  10. int getPre(int x, int y) { return x < 0 || y < 0 ? 0 : pre[x][y]; }
  11.  
  12. int main() {
  13. scanf("%d %d %d", &n, &m, &p);
  14. for (int i = 0; i < n; ++i) {
  15. for (int j = 0; j < m; ++j) {
  16. scanf("%d", &a[i][j]);
  17. }
  18. }
  19.  
  20. for (int i = 0; i < n; ++i) {
  21. for (int j = 0; j < m; ++j) {
  22. pre[i][j] = getPre(i-1, j) + getPre(i, j-1) - getPre(i-1, j-1);
  23. a[i][j] -= pre[i][j] - getPre(i-p, j) - getPre(i, j-p) + getPre(i-p, j-p);
  24.  
  25. if (a[i][j] < 0) return 0 * printf("TIDAK\n");
  26. if ((i > n-p || j > m-p) && a[i][j] != 0) return 0 * printf("TIDAK\n");
  27.  
  28. pre[i][j] += a[i][j];
  29. }
  30. }
  31.  
  32. printf("YA\n");
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 4420KB
stdin
3 3 2
1 2 1
2 4 2
1 2 1
stdout
YA