fork(6) download
  1. #!perl -pa
  2. $_=(1x($x=2/($y=pop@F)*map{1..$_}@F)."
  3. ")x$y;sub
  4. f{my$l=$_;$-|=!@_;for$=(@_){$Z=_
  5. x~-$=;$f=0;s/1{$=}1{$=}/[$Z$Z]/&!/\]..{$x}\[/s&&f(grep$=ne$_||$f++,@_);$-or$_=$l;}}f@F
Success #stdin #stdout 2.56s 6000KB
stdin
1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 5
stdout
[][__][__]
[__][__][]
[][__][__]
[__][__][]
[][__][__]