fork download
  1. ($w, $h, $n) = split/ /,<>;
  2.  
  3. @xy = <>;
  4. chomp @xy;
  5.  
  6. @pyr = @a = (0) x ($w + 1);
  7.  
  8. for $i(1..$n){
  9. ($x, $y)= split/ /, $xy[$i-1];
  10. if (abs($x-$y) >= $h - $pyr[$y]){
  11. print "bad answer: ";
  12. print $i, $/;
  13. }
  14.  
  15. $a[$y]++;
  16. $pyr[$y] < $a[$y] and $pyr[$y] = $a[$y];
  17.  
  18. $j = $y;
  19. while($j > 1 and $pyr[$j-1] < $pyr[$j]-1){
  20. $pyr[--$j]++
  21. }
  22.  
  23. $j = $y;
  24. while($j < $w and $pyr[$j+1] < $pyr[$j]-1){
  25. $pyr[++$j]++
  26. }
  27.  
  28. print "\@a : @a",$/;
  29. print "\@pyr: @pyr", "\n---",$/;
  30. }
  31.  
  32. print "good answer: ";
  33. print 0, $/
Success #stdin #stdout 0s 3564KB
stdin
5 5 10
1 1
1 1
1 1
5 5
5 5
3 3
2 2
1 1
3 3
3 3
stdout
@a  : 0 1 0 0 0 0
@pyr: 0 1 0 0 0 0
---
@a  : 0 2 0 0 0 0
@pyr: 0 2 1 0 0 0
---
@a  : 0 3 0 0 0 0
@pyr: 0 3 2 1 0 0
---
@a  : 0 3 0 0 0 1
@pyr: 0 3 2 1 0 1
---
@a  : 0 3 0 0 0 2
@pyr: 0 3 2 1 1 2
---
@a  : 0 3 0 1 0 2
@pyr: 0 3 2 1 1 2
---
@a  : 0 3 1 1 0 2
@pyr: 0 3 2 1 1 2
---
@a  : 0 4 1 1 0 2
@pyr: 0 4 3 2 1 2
---
@a  : 0 4 1 2 0 2
@pyr: 0 4 3 2 1 2
---
@a  : 0 4 1 3 0 2
@pyr: 0 4 3 3 2 2
---
good answer: 0