Simple rust solution
Enumerate corner cells, extend horizontally and vertically. There are four cornered paths to consider for each corner cell. Use prefix sum to quickly calculate 
Enumerate corner cells, extend horizontally and vertically. There are four cornered paths to consider for each corner cell. Use prefix sum to quickly calculate zeros for each path.\n\n# Complexity\n- Time complexity:\n$$O(m*n)$$\n\n- Space complexity:\n$$O(m*n)$$\n\n# Code\n```\nimpl Solution {\n    pub fn max_trailing_zeros(grid: Vec<Vec<i32>>) -> i32 {\n        use std::ops::{Add, Sub};\n\n        let m = grid.len();\n        let n = grid[0].len();\n\n        #[derive(Clone, Copy, Debug, Default)]\n        struct Counts {\n            count_2: i32,\n            count_5: i32,\n        }\n\n        impl Counts {\n            fn zeros(&self) -> i32 {\n                self.count_2.min(self.count_5)\n            }\n        }\n\n        impl Add for Counts {\n            type Output = Self;\n            fn add(self, rhs: Self) -> Self::Output {\n                Self {\n                    count_2: self.count_2 + rhs.count_2,\n                    count_5: self.count_5 + rhs.count_5,\n                }\n            }\n        }\n\n        impl Sub for Counts {\n            type Output = Self;\n            fn sub(self, rhs: Self) -> Self::Output {\n                Self {\n                    count_2: self.count_2 - rhs.count_2,\n                    count_5: self.count_5 - rhs.count_5,\n                }\n            }\n        }\n\n        let mut prime_count = vec![Counts::default(); 1001];\n        for i in 2..=1000 {\n            let mut count_2 = 0;\n            let mut count_5 = 0;\n            let mut k = i;\n            while k % 2 == 0 {\n                k /= 2;\n                count_2 += 1;\n            }\n            while k % 5 == 0 {\n                k /= 5;\n                count_5 += 1;\n            }\n            prime_count[i] = Counts { count_2, count_5 };\n        }\n        let mut h_acc = vec![vec![Counts::default(); n + 1]; m + 1];\n        let mut v_acc = vec![vec![Counts::default(); m + 1]; n + 1];\n\n        for row in 0..m {\n            for col in 0..n {\n                let count = prime_count[grid[row][col] as usize];\n                h_acc[row][col + 1] = h_acc[row][col] + count;\n                v_acc[col][row + 1] = v_acc[col][row] + count;\n            }\n        }\n\n        let mut res = 0;\n\n        for row in 0..m {\n            for col in 0..n {\n                let top = v_acc[col][row];\n                let bottom = v_acc[col][m] - v_acc[col][row + 1];\n                let left = h_acc[row][col];\n                let right = h_acc[row][n] - h_acc[row][col + 1];\n                let current = prime_count[grid[row][col] as usize];\n\n                res = res.max(\n                    (top + left + current).zeros()\n                ).max(\n                    (top + right + current).zeros()\n                ).max(\n                    (bottom + left + current).zeros()\n                ).max(\n                    (bottom + right + current).zeros()\n                );\n            }\n        }\n\n        res\n    }\n}\n```
['Rust']