C++ solution, faster than 90%, O(m*n), Simple
\nclass Solution {\npublic:\n    class data{\n        public:\n        int up_5, up_2,\n            left_5, left_2;\n        };\n    vector<vector<data>> v;\n  
```\nclass Solution {\npublic:\n    class data{\n        public:\n        int up_5, up_2,\n            left_5, left_2;\n        };\n    vector<vector<data>> v;\n    int func2(int n)\n    {\n        int res=0;\n        while(n%2==0){ res++; n/=2;}\n        return res;\n    }\n    int func5(int n)\n    {\n        int res=0;\n        while(n%5==0){ res++; n/=5;}\n        return res;\n    }\n    int sol(int x1, int x2, int y1, int y2, int z1, int z2)\n    {\n        return min(x1+y1+z1, x2+y2+z2);\n    }\n    int func(int i, int j, vector<vector<int>> &g, data H, data V)\n    {\n        int res=0;\n        data cur=v[i][j];\n        \n        int cnt_2=func2(g[i][j]), cnt_5=func5(g[i][j]);\n        res=max(res, sol(-cnt_2, -cnt_5, cur.left_2, cur.left_5, cur.up_2, cur.up_5));\n        res=max(res, sol(0,0,cur.left_2,cur.left_5,V.up_2-cur.up_2,V.up_5-cur.up_5));\n        res=max(res, sol(0,0,cur.up_2,cur.up_5,H.left_2-cur.left_2,H.left_5-cur.left_5));\n        res=max(res, sol(cnt_2,cnt_5,V.up_2-cur.up_2,V.up_5-cur.up_5,H.left_2-cur.left_2, H.left_5-cur.left_5));\n        return res;\n    }\n    int maxTrailingZeros(vector<vector<int>>& g) {\n        int m=g.size(), n=g[0].size();\n        v.assign(m+1, vector<data>(n+1));\n        for(int i=0; i<m; i++)\n        {\n            for(int j=0; j<n; j++)\n            {\n                if(i==0){\n                    v[i][j].up_2=func2(g[i][j]); v[i][j].up_5=func5(g[i][j]);\n                }else{\n                    v[i][j].up_2=v[i-1][j].up_2+func2(g[i][j]); \n                    v[i][j].up_5=v[i-1][j].up_5+func5(g[i][j]);\n                }\n                if(j==0){\n                    v[i][j].left_2=func2(g[i][j]); v[i][j].left_5=func5(g[i][j]);\n                }else{\n                    v[i][j].left_2=v[i][j-1].left_2+func2(g[i][j]); \n                    v[i][j].left_5=v[i][j-1].left_5+func5(g[i][j]);\n                }\n            }\n        }\n        \n        int res=0;\n        for(int i=0; i<m; i++)\n            for(int j=0; j<n; j++)\n                res=max(res, func(i, j, g, v[i][n-1], v[m-1][j]));\n        return res;\n    }\n};\n```
[]