fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1e3+5;
  5. int a[N][N], pre_h[N][N], pre_c[N][N], ans = 0;
  6.  
  7.  
  8. int main(){
  9. int m, n, k;cin >> m >> n >> k;
  10. // << pre_h[1][0];
  11. for(int i = 1; i <= m;i++){
  12. for(int j = 1; j <= n; j++){
  13. cin >> a[i][j];
  14. pre_h[i][j] = pre_h[i][j-1] + a[i][j];
  15. //cout << pre_h[i][j] << " ";
  16. pre_c[i][j] = pre_c[i-1][j] + a[i][j];
  17. }
  18. //cout << endl;
  19. }
  20. for(int i = 1; i <= m;i++){
  21. for(int j = k; j <= n;j++){
  22. if ((pre_h[i][j] - pre_h[i][j-k])%k==0) ans++;
  23. }
  24. }
  25. for(int j = 1; j <= n;j++){
  26. for(int i = k; i <= m;i++){
  27. if ((pre_c[i][j] - pre_c[i-k][j])%k==0) ans++;
  28. }
  29. }
  30. cout << ans;
  31. }
  32.  
Success #stdin #stdout 0.01s 5616KB
stdin
3 4 3
1 2 3 4
2 4 6 8
3 5 7 1
stdout
6