fork download
  1. /* paiza POH! vol.2
  2.  * result:
  3.  * http://p...content-available-to-author-only...a.jp/poh/paizen/result/49b109cda01f53abda3129b43c143c38
  4.  * author: Leonardone @ NEETSDKASU
  5.  */
  6. #include <cstdio>
  7. using namespace std;
  8.  
  9. #define OUTPUTSIZE (600000)
  10. char output[OUTPUTSIZE];
  11. char *optr = output;
  12.  
  13. inline void putInt(int v) {
  14. if (v < 10) {
  15. *optr = '0' + (char)v;
  16. ++optr;
  17. } else {
  18. putInt(v / 10);
  19. *optr = '0' + (char)(v % 10);
  20. ++optr;
  21. }
  22. }
  23.  
  24. inline void putNewline() {
  25. *optr = '\n';
  26. ++optr;
  27. }
  28.  
  29. #define BUFSIZE (900000)
  30. char buf[BUFSIZE];
  31. char *ptr = buf;
  32.  
  33. inline int getInt() {
  34. int v = 0;
  35. while (*ptr < '0' || *ptr > '9') ++ptr;
  36. while (*ptr >= '0' && *ptr <= '9') {
  37. v = 10 * v + (int)(*ptr - '0');
  38. ++ptr;
  39. }
  40. return v;
  41. }
  42.  
  43. inline char getChar() {
  44. while (*ptr < '0' || *ptr > '9') ++ptr;
  45. return *ptr++;
  46. }
  47.  
  48. int space2top[301];
  49. int table[301][301];
  50.  
  51. typedef int * PINT;
  52.  
  53. int main() {
  54. int H, W, N, s, t, i, x, y;
  55. char str[310];
  56. PINT p, q;
  57.  
  58. fread(buf, sizeof(char), BUFSIZE, stdin);
  59.  
  60. H = getInt();
  61. W = getInt();
  62.  
  63. for (y = 0; y < H; ++y) {
  64. q = space2top + 1;
  65. for (x = 0; x < W; ++x, ++q) {
  66. if (getChar() == '0') {
  67. p = q;
  68. s = ++(*p);
  69. t = 1;
  70. while (*p) {
  71. if (*p < s) {
  72. s = *p;
  73. }
  74. ++table[t][s];
  75. ++t;
  76. --p;
  77. }
  78. } else {
  79. *q = 0;
  80. }
  81. }
  82. }
  83.  
  84. for (x = 1; x <= W; ++x) {
  85. p = table[x] + H;
  86. for (y = 1; y < H; ++y) {
  87. --p;
  88. *p += *(p + 1);
  89. }
  90. }
  91.  
  92. N = getInt();
  93.  
  94. for (i = 0; i < N; ++i) {
  95. s = getInt();
  96. t = getInt();
  97. putInt(table[t][s]);
  98. putNewline();
  99. }
  100.  
  101. fwrite(output, sizeof(char), (int)optr - (int)output, stdout);
  102.  
  103. return 0;
  104. }
  105.  
Success #stdin #stdout 0s 5164KB
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