#984479

Solution for 0151: Grid by tnakao

Source Code Status Test Cases
    Policy: public     Reviewed: 51    
00.25 sec    6472 KB    81 lines     1119 bytes    2014-06-15 18:49
### main

while true
  n = gets.strip.to_i
  break if n == 0

  grid = []
  n.times.each do
    hl = gets.strip.split('').map{|s| s == "1"}
    grid << hl
  end

  max_c = 0

  # horizontal
  for y in (0...n)
    c = 0
    for x in (0...n)
      if grid[y][x]
        c += 1
        max_c = c if max_c < c
      else
        c = 0
      end
    end
  end

  # vertical
  for x in (0...n)
    c = 0
    for y in (0...n)
      if grid[y][x]
        c += 1
        max_c = c if max_c < c
      else
        c = 0
      end
    end
  end

  # diagonal (top-right -> bottom-left)
  nn = 2 * n - 2
  for d in (0..nn)
    c = 0
    x = 0
    y = d - x
    while x < n && y >= 0
      if y < n && grid[y][x]
        c += 1
        max_c = c if max_c < c
      else
        c = 0
      end

      x += 1
      y -= 1
    end
  end

  # diagonal (top-left -> bottom-right)
  for d in (-(n - 1)..(n - 1))
    c = 0
    x = 0
    y = x + d
    while x < n && y < n
      if y >= 0 && grid[y][x]
        c +=1
        max_c = c if max_c < c
      else
        c = 0
      end

      x += 1
      y += 1
    end
  end

  p max_c
end


Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 1/1 Ruby CPU: 00.25 sec Memory: 6472 KB Length: 1119 B 2014-06-15 18:49 2014-06-15 18:49
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 00.25 sec 6472 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags