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. for(int i = 1; i <= m;i++){
  11. for(int j = 1; j <= n; j++){
  12. cin >> a[i][j];
  13. pre_h[i][j] = pre_h[i][j-1] + a[i][j];
  14. pre_c[i][j] = pre_c[i-1][j] + a[i][j];
  15. }
  16. }
  17. for(int i = 1; i <= m;i++){
  18. for(int j = 1; j <= n;j++){
  19. if ((pre_h[i][j+k-1] - pre_h[i][j-1])%k==0) ans++;
  20. }
  21. }
  22. for(int j = 1; j <= n;j++){
  23. for(int i = 1; i <= m;i++){
  24. if ((pre_c[i+k-1][j] - pre_c[i-1][j])%k==0) ans++;
  25. }
  26. }
  27. cout << ans;
  28. }
  29.  
Success #stdin #stdout 0.01s 5648KB
stdin
3 4 3
1 2 3 4
2 4 6 8
3 5 7 1
stdout
16