fork download
  1. def dfs(x,y,nprev)
  2. if x<0||$a[0].size<=x || y<0||$a.size<=y || $a[y][x]<=nprev
  3. return 0
  4. end
  5. if $memo[[x,y]]
  6. return $memo[[x,y]]
  7. end
  8. n=[[-1,0],[1,0],[0,-1],[0,1]].map{|_x,_y|
  9. dfs(x+_x,y+_y,$a[y][x])+1
  10. }.max
  11. $memo[[x,y]]=n
  12. end
  13. while gets
  14. $a=$_.chomp.split('/').map{|e|e.split('').map(&:to_i)}
  15. $memo={}
  16. p $a.size.times.map{|y|$a[0].size.times.map{|x|dfs(x,y,-1)}.max}.max
  17. end
Success #stdin #stdout 0.02s 7460KB
stdin
01224/82925/69076/32298/21065
stdout
6