Hint 1
One solution is to count ones in each direction separately and find the longest line. Don't you think it will take too much lines of code?
Hint 2
Is it possible to use some extra space to make the solution simple?
Hint 3
Can we use dynamic programming to make use of intermediate results?
Hint 4
Think of a 3D array which can be used to store the longest line obtained so far for each direction.