Given an `m x n` binary matrix `mat`, return _the length of the longest line of consecutive one in the matrix_.

The line could be horizontal, vertical, diagonal, or anti-diagonal.

**Example 1:**

**Input:** mat = \[\[0,1,1,0\],\[0,1,1,0\],\[0,0,0,1\]\]
**Output:** 3

**Example 2:**

**Input:** mat = \[\[1,1,1,1\],\[0,1,1,0\],\[0,0,0,1\]\]
**Output:** 4

**Constraints:**

*   `m == mat.length`
*   `n == mat[i].length`
*   `1 <= m, n <= 104`
*   `1 <= m * n <= 104`
*   `mat[i][j]` is either `0` or `1`.


def longestLine(mat):
    rows, cols = len(mat), len(mat[0])
    max_length = 0
    dp = [[[0, 0, 0, 0] for _ in range(cols)] for _ in range(rows)]

    for r in range(rows):
        for c in range(cols):
            if mat[r][c] == 1:
                dp[r][c][0] = dp[r - 1][c][0] + 1 if r > 0 else 1
                dp[r][c][1] = dp[r][c - 1][1] + 1 if c > 0 else 1
                dp[r][c][2] = dp[r - 1][c - 1][2] + 1 if r > 0 and c > 0 else 1
                dp[r][c][3] = dp[r - 1][c + 1][3] + 1 if r > 0 and c < cols - 1 else 1
                max_length = max(max_length, max(dp[r][c]))

    return max_length
