#1496687

Solution for 0179: Mysterious Worm by iwamot

Source Code Status Test Cases
    Policy: public     Reviewed: 132    
02.29 sec    11108 KB    27 lines     386 bytes    2015-08-29 22:39
def bfs(bug)
  secs = {bug => 0}
  q = [bug]

  while b = q.shift
    return secs[b] if b.split(//).uniq.size == 1

    0.upto(b.size - 2) do |i|
      next if b[i] == b[i + 1]

      bt = b.dup
      bt[i, 2] = 'rgb'.delete(b[i, 2]) * 2
      next if secs[bt]

      secs[bt] = secs[b] + 1
      q.push bt
    end
  end

  'NA'
end

until (bug = gets.chomp) == '0'
  puts bfs(bug)
end


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

Status
Judge: 1/1 Ruby CPU: 02.29 sec Memory: 11108 KB Length: 386 B 2015-08-29 22:39 2015-08-29 22:39
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 02.29 sec 11108 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags