fork download
  1. N=Struct.new:l
  2. G=->c{n=[]
  3. c.map{|m|m<1?n<<N.new([]):m<2?(w=N.new([])
  4. n.map{|x|x.l<<w;w.l<<x}
  5. n<<w):(n-=r=n.select{|x|x.l.size%m<1}
  6. n.map{|x|x.l-=r})}
  7. n.size}
  8.  
  9. #--------------------------------------------------
  10.  
  11. require "minitest/autorun"
  12.  
  13. class TestGraph < MiniTest::Unit::TestCase
  14. def test_empty
  15. assert_equal 0, result([])
  16. end
  17. def test_1
  18. assert_equal 4, result([0,1,0,1,0,1,3])
  19. end
  20. def test_2
  21. assert_equal 0, result([5])
  22. end
  23. def test_3
  24. assert_equal 0, result([0, 0, 0, 11])
  25. end
  26. def test_4
  27. assert_equal 6, result([0,0,0,1,1,1])
  28. end
  29. def test_5
  30. assert_equal 6, result([0,0,1,1,0,0,1,1,2,5,7,0,1])
  31. end
  32. def test_6
  33. assert_equal 6, result([0,0,1,1,1,1,5,1,4,3,1,0,0,0,1,2])
  34. end
  35. def test_7
  36. assert_equal 8, result([0,0,1,1,0,0,1,1,5,2,3,0,0,1,1,0,0,1,1,3,4,0,0,1,1,2,1,1])
  37. end
  38. def test_8
  39. assert_equal 14, result([0,0,1,1,0,0,1,1,2,5,7,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,8])
  40. end
  41.  
  42. def result(commands)
  43. G[commands]
  44. end
  45. end
Success #stdin #stdout 0.06s 8640KB
stdin
Standard input is empty
stdout
Run options: --seed 54304

# Running tests:

.........

Finished tests in 0.009386s, 958.8566 tests/s, 958.8566 assertions/s.

9 tests, 9 assertions, 0 failures, 0 errors, 0 skips