fork(1) download
  1. #!/usr/bin/perl -p
  2. # initialisation added to pass all inputs at once
  3. @l=(); @h=(); $p=undef;
  4.  
  5. # golfed code
  6. $p.="([#_]{$_})[x_]+"for@l=split;chop$p,$_=<>;/^[x_]*$p*$(?{$h[$_-1].=$$_ for 1..@l})(?!)/;$_=@h?join$",grep{$h[$_]!~/_/}0..$#l:ERROR;
  7.  
  8. # append "\n" for clearer output
  9. $_.="\n";
  10.  
  11.  
  12.  
Success #stdin #stdout 0s 6000KB
stdin
3 6 1 4 6
###x######x#x####x######
1 2 1
#____xx___##__x_#
1 2 1
____#___x
1 2 1
#_#x_#
1 2 1
#____#
1 1 1 1
__#_______#____
4 4
______x####________
4 4
__x####________
3
__x__
5 1 3
x#####x____#____
stdout
0 1 2 3 4
0 1 2

ERROR
0 2


0
ERROR
0