fork(1) download
  1. /* paiza POH!vol.2
  2.  * result:
  3.  * http://p...content-available-to-author-only...a.jp/poh/paizen/result/965285167fbbc3cc916891875d5d798b
  4.  * author: Leonardone @ NEETSDKASU
  5.  */
  6. #include <stdio.h>
  7.  
  8. char input[100000];
  9. char *ptr = input;
  10.  
  11. int getInt(void) {
  12. int v = 0;
  13. while (*ptr < '0' || *ptr > '9') ++ptr;
  14. while (*ptr >= '0' && *ptr <= '9')
  15. {
  16. v = 10 * v + (int)(*ptr - '0');
  17. ++ptr;
  18. }
  19. return v;
  20. }
  21.  
  22. char getChar(void) {
  23. while (*ptr < '0' || *ptr > '9') ++ptr;
  24. return *ptr++;
  25. }
  26.  
  27. void putInt(int v) {
  28. if (v < 10) {
  29. putchar('0' + (char)v);
  30. } else {
  31. putInt(v / 10);
  32. putchar('0' + (char)(v % 10));
  33. }
  34. }
  35.  
  36. int home[300][300];
  37. int hoge[300][300];
  38.  
  39. int main(void) {
  40. int H, W, N, s, t;
  41. int x, y, c, i;
  42. int hx, hy, hxe, hye;
  43. int count, dy, dx;
  44. char ch;
  45. fread(input, sizeof(char), 100000, stdin);
  46. H = getInt();
  47. W = getInt();
  48.  
  49. for (y = 0; y < H; ++y) {
  50. c = 0;
  51. for (x = 0; x < W; ++x) {
  52. ch = getChar();
  53. if (ch == '0') {
  54. c++;
  55. if (y) {
  56. hoge[y][x] = hoge[y - 1][x] + 1;
  57. } else {
  58. hoge[y][x] = 1;
  59. }
  60. } else {
  61. c = 0;
  62. hoge[y][x] = 0;
  63. }
  64. home[y][x] = c;
  65. }
  66. }
  67.  
  68. N = getInt();
  69.  
  70. for (i = 0; i < N; ++i) {
  71. s = getInt();
  72. t = getInt();
  73.  
  74. if (s > H || t > W) {
  75. putchar('0');
  76. putchar('\n');
  77. continue;
  78. }
  79.  
  80. hye = s - 1;
  81. hxe = t - 1;
  82. count = 0;
  83. for (hy = H - 1; hy >= hye; --hy) {
  84. for (hx = W - 1; hx >= hxe; --hx) {
  85. if (home[hy][hx] < t) {
  86. hx -= home[hy][hx];
  87. continue;
  88. }
  89. if (hoge[hy][hx] < s) {
  90. continue;
  91. }
  92. for (dy = 1; dy < s; ++dy) {
  93. y = hy - dy;
  94. if (y < 0) {
  95. break;
  96. }
  97. if (home[y][hx] < t) {
  98. break;
  99. }
  100. }
  101. if (dy == s) {
  102. count++;
  103. }
  104. }
  105. }
  106. putInt(count);
  107. putchar('\n');
  108. }
  109.  
  110. return 0;
  111. }
  112.  
Success #stdin #stdout 0s 3096KB
stdin
5 5
00000
00100
00010
10001
10000
3
2 2
1 1
3 2
stdout
6
20
2