My Solution
\n/**\n * Time Complexity: O(rows * cols)\n * Space Complexity: O(rows * cols)\n * where `rows` is the number of the rows of the grid `grid`\n *       `cols` is
```\n/**\n * Time Complexity: O(rows * cols)\n * Space Complexity: O(rows * cols)\n * where `rows` is the number of the rows of the grid `grid`\n *       `cols` is the number of the columns of the grid `grid`\n */\nclass Solution {\n private:\n  class Stat {\n   public:\n    Stat(): factor2s_(0), factor5s_(0) {\n    }\n    \n    Stat(const int factor2s, const int factor5s): factor2s_(factor2s), factor5s_(factor5s) {\n    }\n    \n    Stat(const int number) : factor2s_(get_factors(number, factor_2)), factor5s_(get_factors(number, factor_5)) {\n    }\n    \n    Stat operator+(const Stat &rhs) {\n      return Stat(factor2s_ + rhs.factor2s_, factor5s_ + rhs.factor5s_);\n    }\n    \n    Stat operator-(const Stat &rhs) {\n      return Stat(factor2s_ - rhs.factor2s_, factor5s_ - rhs.factor5s_);\n    }\n    \n    int zeros() const {\n      return min(factor2s_, factor5s_);\n    }\n    \n   private:\n    int get_factors(const int number, const int factor) {\n      int ret = 0;\n      for (int num = number; num % factor == 0; num /= factor) {\n        ++ret;\n      }\n      return ret;\n    }\n    \n    static constexpr int factor_2 = 2;\n    static constexpr int factor_5 = 5;\n\n    int factor2s_;\n    int factor5s_;\n  };\n  \n public:\n  int maxTrailingZeros(const vector<vector<int>> &grid) {\n    const int rows = static_cast<int>(grid.size());\n    const int cols = static_cast<int>(grid.front().size());\n    Stat row_stats[rows][cols + 1];\n    Stat col_stats[cols][rows + 1];\n    for (int r = 0; r < rows; ++r) {\n      for (int c = 0; c < cols; ++c) {\n        Stat stat(grid[r][c]);\n        row_stats[r][c + 1] = row_stats[r][c] + stat;\n        col_stats[c][r + 1] = col_stats[c][r] + stat;\n      }\n    }\n    \n    int ret = 0;\n    for (int r = 0; r < rows; ++r) {\n      for (int c = 0; c < cols; ++c) {\n        Stat left = row_stats[r][c + 1];\n        Stat top = col_stats[c][r];\n        Stat right = row_stats[r][cols] - row_stats[r][c];\n        Stat bottom = col_stats[c][rows] - col_stats[c][r + 1];\n        ret = max({ret, (left + top).zeros(), (right + top).zeros(), (left + bottom).zeros(), (right + bottom).zeros()});\n      }\n    }\n    return ret;\n  }\n};\n```
[]