fork download
  1. #!/usr/bin/perl
  2. # paiza POH! vol.2
  3. # result:
  4. # http://p...content-available-to-author-only...a.jp/poh/paizen/result/65cb7f2104cbaa627523285727875758
  5. # author: Leonardone @ NEETSDKASU
  6.  
  7. @hw = split(' ', <STDIN>);
  8. $h = int($hw[0]);
  9. $w = int($hw[1]);
  10.  
  11. @sp;
  12. @tb;
  13. for $y (0 .. $h - 1) {
  14. @line = split('', <STDIN>);
  15. for $x (0 .. $w - 1) {
  16. if ($line[$x] == '0') {
  17. $sp[$x]++;
  18. $s = $sp[$x];
  19. $t = 1;
  20. for ($i = $x; $i >= 0 && $sp[$i] > 0; $i--) {
  21. if ($sp[$i] < $s) {
  22. $s = $sp[$i];
  23. }
  24. $tb[$s][$t]++;
  25. $t++;
  26. }
  27. } else {
  28. $sp[$x] = 0;
  29. }
  30. }
  31. }
  32.  
  33. for $x (1 .. $w) {
  34. $tb[$h][$x] += 0;
  35. for ($y = $h - 1; $y > 0; $y--) {
  36. $tb[$y][$x] += $tb[$y + 1][$x];
  37. }
  38. }
  39.  
  40. $n = int(<STDIN>);
  41. for (1 .. $n) {
  42. @st = split(' ', <STDIN>);
  43. $s = int($st[0]);
  44. $t = int($st[1]);
  45. if ($s <= $h && $t <= $w) {
  46. print $tb[$s][$t], "\n";
  47. } else {
  48. print "0\n";
  49. }
  50. }
Success #stdin #stdout 0s 3608KB
stdin
5 5
00000
00100
00010
10001
10000
7
2 2
1 1
3 2
3 2
2 3
3 1
1 3
stdout
6
20
2
2
1
6
7