C++ 100% faster (557 ms), 100% less memory (140.6 MB)
The hints 1-4 basically summarized what this code does.\n\ncpp\nstruct s {\n    int five_cnt;\n    int two_cnt;\n    s(int in_f, int in_t) {\n        five_cnt =
The hints 1-4 basically summarized what this code does.\n\n```cpp\nstruct s {\n    int five_cnt;\n    int two_cnt;\n    s(int in_f, int in_t) {\n        five_cnt = in_f;\n        two_cnt = in_t;\n    }\n    s() {}\n};\n\nclass Solution {\npublic:\n    vector<vector<s>> C, VC, HC;\n    int tmpFive, tmpTwo;\n    \n    void setT(int in_val) {\n        tmpFive = 0;\n        tmpTwo = 0;\n        if (in_val == 0) {\n            return;\n        }\n        while ((in_val % 5) == 0) {\n            tmpFive++;\n            in_val /= 5;\n        }\n        while ((in_val % 2) == 0) {\n            tmpTwo++;\n            in_val /= 2;\n        }\n        return;\n    }\n    \n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        C.clear();\n        int row = grid.size();\n        int col = grid[0].size();\n        \n        for (int i = 0; i < row; i++) {\n            vector<s> tmp;\n            C.push_back(tmp);\n            for (int j = 0; j < col; j++) {\n                setT(grid[i][j]);\n                C[i].push_back(s(tmpFive, tmpTwo));\n            }\n        }\n        grid.clear();\n        VC = C;\n        HC = C;\n        C.clear();\n        for (int i = 0; i < row; i++) {\n            for (int j = 1; j < col; j++) {\n                HC[i][j].five_cnt += HC[i][j - 1].five_cnt;\n                HC[i][j].two_cnt += HC[i][j - 1].two_cnt;\n            }\n        }\n        for (int j = 0; j < col; j++) {\n            for (int i = 1; i < row; i++) {\n                VC[i][j].five_cnt += VC[i - 1][j].five_cnt;\n                VC[i][j].two_cnt += VC[i - 1][j].two_cnt;\n            }\n        }\n        int resmaxcnt = 0;\n        for (int i = 0; i < row; i++) {\n            for (int j = 0; j < col; j++) {\n                // vertical, then left.\n                s tmp = VC[i][j];\n                if (j - 1 >= 0) {\n                    tmp.five_cnt += HC[i][j - 1].five_cnt; // correct here.\n                    tmp.two_cnt += HC[i][j - 1].two_cnt;\n                }\n                resmaxcnt = max(resmaxcnt, min(tmp.five_cnt, tmp.two_cnt));\n                // next, vertical, right.\n                tmp = VC[i][j];\n                tmp.five_cnt += HC[i][col - 1].five_cnt - HC[i][j].five_cnt; // correct\n                tmp.two_cnt += HC[i][col - 1].two_cnt - HC[i][j].two_cnt;\n                resmaxcnt = max(resmaxcnt, min(tmp.five_cnt, tmp.two_cnt));\n                \n                // next, bottom - left.\n                // always includes middle in the vertical part.\n                tmp = VC[row - 1][j];\n                if (i - 1 >= 0) {\n                    tmp.five_cnt = VC[row - 1][j].five_cnt - VC[i - 1][j].five_cnt; // modified.\n                    tmp.two_cnt = VC[row - 1][j].two_cnt - VC[i - 1][j].two_cnt;\n                }\n                if (j - 1 >= 0) {\n                    tmp.five_cnt += HC[i][j - 1].five_cnt;\n                    tmp.two_cnt += HC[i][j - 1].two_cnt;\n                }\n                resmaxcnt = max(resmaxcnt, min(tmp.five_cnt, tmp.two_cnt));\n                \n                tmp = VC[row - 1][j]; \n                if (i - 1 >= 0) {\n                    tmp.five_cnt = VC[row - 1][j].five_cnt - VC[i - 1][j].five_cnt;\n                    tmp.two_cnt = VC[row - 1][j].two_cnt - VC[i - 1][j].two_cnt;\n                }\n                tmp.five_cnt += HC[i][col - 1].five_cnt - HC[i][j].five_cnt;\n                tmp.two_cnt += HC[i][col - 1].two_cnt - HC[i][j].two_cnt;\n                resmaxcnt = max(resmaxcnt, min(tmp.five_cnt, tmp.two_cnt));\n            }\n        }\n        return resmaxcnt;\n    }\n};\n```
[]