C++ || solution
\nclass Solution {\npublic:\n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        int m=grid.size();\n        int n=grid[0].size();\n        vector<ve
```\nclass Solution {\npublic:\n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        int m=grid.size();\n        int n=grid[0].size();\n        vector<vector<pair<int,int>>> v(m,vector<pair<int,int>>(n)),u(m,vector<pair<int,int>>(n)),d(m,vector<pair<int,int>>(n)),l(m,vector<pair<int,int>>(n)),r(m,vector<pair<int,int>>(n));\n        \n        for(int i=0;i<m;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                int x=grid[i][j];\n                v[i][j].first=0;\n                v[i][j].second=0;\n                while(x%2==0)\n                {\n                    x/=2;\n                    v[i][j].first++;\n                }\n                while(x%5==0)\n                {\n                    x/=5;\n                    v[i][j].second++;\n                }\n            }\n        }\n        u=v;\n        d=v;\n        l=v;\n        r=v;\n        \n        for(int i=0;i<m;i++)\n        {\n            for(int j=1;j<n;j++)\n            {\n                l[i][j].first+=l[i][j-1].first;\n                l[i][j].second+=l[i][j-1].second;\n                \n                r[i][n-j-1].first+=r[i][n-j].first;\n                r[i][n-j-1].second+=r[i][n-j].second;\n            }            \n        }\n        \n        for(int i=0;i<n;i++)\n        {\n            for(int j=1;j<m;j++)\n            {\n                u[j][i].first+=u[j-1][i].first;\n                u[j][i].second+=u[j-1][i].second;\n                \n                d[m-j-1][i].first+=d[m-j][i].first;\n                d[m-j-1][i].second+=d[m-j][i].second;\n            }            \n        }\n        int res=0;\n        for(int i=0;i<m;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                \n                int x1=u[i][j].first;\n                int x2=u[i][j].second;\n                int x3=l[i][j].first;\n                int x4=l[i][j].second;\n                \n                int c2=x1+x3-v[i][j].first;\n                int c5=x2+x4-v[i][j].second;\n                res=max(res,min(c2,c5));\n                //####################################\n                x1=u[i][j].first;\n                x2=u[i][j].second;\n                x3=r[i][j].first;\n                x4=r[i][j].second;\n                \n                c2=x1+x3-v[i][j].first;\n                c5=x2+x4-v[i][j].second;\n                res=max(res,min(c2,c5));\n                \n                //####################################\n                x1=d[i][j].first;\n                x2=d[i][j].second;\n                x3=r[i][j].first;\n                x4=r[i][j].second;\n                \n                c2=x1+x3-v[i][j].first;\n                c5=x2+x4-v[i][j].second;\n                res=max(res,min(c2,c5));\n                //####################################\n                x1=d[i][j].first;\n                x2=d[i][j].second;\n                x3=l[i][j].first;\n                x4=l[i][j].second;\n                \n                c2=x1+x3-v[i][j].first;\n                c5=x2+x4-v[i][j].second;\n                res=max(res,min(c2,c5));\n                \n            }\n        }\n        return res;\n        \n    }\n};\n```
[]