C++ solution
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int maxTrailingZeros(vector<vector<int>>& grid) {
        int m = grid.size(),n = grid[0].size();
        vector<vector<pair<int,int>>> v(m+1,vector<pair<int,int>> (n+1));
        for (int i=1;i<=m;i++){
            for (int j=1;j<=n;j++){
                while (grid[i-1][j-1]%5==0){
                    v[i][j].first++;
                    grid[i-1][j-1]/=5;
                }
                while (grid[i-1][j-1]%2==0){
                    v[i][j].second++;
                    grid[i-1][j-1]/=2;
                }
            }
        }
        vector<vector<pair<int,int>>> hor = v,ver = v;
        for (int i=1;i<=m;i++){
            for (int j=1;j<=n;j++){
                hor[i][j].first += hor[i][j-1].first;
                hor[i][j].second += hor[i][j-1].second;
            }
        }

        for (int j=1;j<=n;j++){
            for (int i=1;i<=m;i++){
                ver[i][j].first += ver[i-1][j].first;
                ver[i][j].second += ver[i-1][j].second;
            }
        }

        int ans = 0;
        for (int i=1;i<=m;i++){
            for (int j=1;j<=n;j++){
                ans = max(ans,min(ver[i][j].first+hor[i][j].first-v[i][j].first,ver[i][j].second+hor[i][j].second-v[i][j].second));
                ans = max(ans,min(ver[m][j].first-ver[i][j].first+hor[i][j].first,ver[m][j].second-ver[i][j].second+hor[i][j].second));
                ans = max(ans,min(ver[i][j].first+hor[i][n].first-hor[i][j].first,ver[i][j].second+hor[i][n].second-hor[i][j].second));
                ans = max(ans,min(ver[m][j].first-ver[i][j].first+hor[i][n].first-hor[i][j].first+v[i][j].first,ver[m][j].second-ver[i][j].second+hor[i][n].second-hor[i][j].second+v[i][j].second));
            }
        }

        return ans;

        
        
    }
};
```
['C++']