C++ 100% Fast
\nclass Solution {\npublic:\n    int maxTrailingZeros(vector<vector<int>>& grid) \n    {\n        int m=grid.size(),n=grid[0].size();\n        vector<vector<pai
```\nclass Solution {\npublic:\n    int maxTrailingZeros(vector<vector<int>>& grid) \n    {\n        int m=grid.size(),n=grid[0].size();\n        vector<vector<pair<int,int>>>prefix(m,vector<pair<int,int>>(n,{0,0}));\n        for(int i=0;i<m;i++)\n            for(int j=0;j<n;j++)\n            {\n                int cnt1=0,cnt2=0;\n                while(grid[i][j]%2==0)cnt1++,grid[i][j]/=2;\n                while(grid[i][j]%5==0)cnt2++,grid[i][j]/=5;\n                prefix[i][j].first=cnt1;\n                prefix[i][j].second=cnt2;\n            }\n        auto record=prefix;\n        for(int i=0;i<m;i++)\n            for(int j=1;j<n;j++)\n            {\n                prefix[i][j].first+=prefix[i][j-1].first;\n                prefix[i][j].second+=prefix[i][j-1].second;\n            }\n        int ans=0;\n        for(int i=0;i<n;i++)\n        {\n            int v1=0,v2=0;\n            for(int j=0;j<m;j++)\n            {\n                ans=max(ans,min(v1+prefix[j][i].first,v2+prefix[j][i].second));\n                int v3=prefix[j][n-1].first,v4=prefix[j][n-1].second;\n                if(i-1>=0)v3-=prefix[j][i-1].first,v4-=prefix[j][i-1].second;\n                ans=max(ans,min(v1+v3,v2+v4));\n                v1+=record[j][i].first,v2+=record[j][i].second;\n            }\n        }\n        for(int i=0;i<n;i++)\n        {\n            int v1=0,v2=0;\n            for(int j=m-1;j>=0;j--)\n            {\n                ans=max(ans,min(v1+prefix[j][i].first,v2+prefix[j][i].second));\n                int v3=prefix[j][n-1].first,v4=prefix[j][n-1].second;\n                if(i-1>=0)v3-=prefix[j][i-1].first,v4-=prefix[j][i-1].second;\n                ans=max(ans,min(v1+v3,v2+v4));\n                v1+=record[j][i].first,v2+=record[j][i].second;\n            }\n        }\n        return ans;\n    }\n};\n```
['Prefix Sum']