1464 ms
ruby\ndef max_trailing_zeros v\n    y, x = v.size, v[0].size\n    m, h = 0, Array.new(y) { [0] * x }\n    for i in 0...y\n        h2, h5 = 0, 0\n        for j i
```ruby\ndef max_trailing_zeros v\n    y, x = v.size, v[0].size\n    m, h = 0, Array.new(y) { [0] * x }\n    for i in 0...y\n        h2, h5 = 0, 0\n        for j in 0...x\n            d = v[i][j]\n            x2, x5 = 0, 0\n            (d >>= 1; x2 += 1) while (d & 1).zero?\n            (d  /= 5; x5 += 1) while (d % 5).zero?\n            h[i][j] = [h2 += x2, h5 += x5]\n            if i > 0\n                p2, p5 = *v[i - 1][j]\n                x2 += p2; x5 += p5\n            end\n            v[i][j] = [x2, x5]\n        end\n    end\n    for i in 0...y\n        r2, r5 = *h[i][-1]\n        for j in 0...x\n             v2,  v5 = *v[-1][j]\n            cv2, cv5 = *v[i][j]\n            ch2, ch5 = *h[i][j]\n            j > 0 ?\n                (lh2, lh5 = *h[i][j - 1]) :\n                (lh2, lh5 = 0, 0)\n            m = [m,\n                 [lh2 + cv2,\n                  lh5 + cv5].min,\n                 [cv2 + r2 - ch2,\n                  cv5 + r5 - ch5].min,\n                 [ch2 + v2 - cv2,\n                  ch5 + v5 - cv5].min,\n                 [r2 - lh2 + v2 - cv2,\n                  r5 - lh5 + v5 - cv5].min\n            ].max\n        end\n    end\n    m\nend\n```
['Ruby']