fork(1) download
  1. /* paiza POH! vol.2
  2.  * result:
  3.  * http://p...content-available-to-author-only...a.jp/poh/paizen/result/0f10ad2fd6a7a8c316333bbb79a54ac9
  4.  * author: Leonardone @ NEETSDKASU
  5.  */
  6. #include <stdio.h>
  7.  
  8. int space2top[301];
  9. int table[301][301];
  10.  
  11. typedef int * PINT;
  12.  
  13. int main(void) {
  14. int H, W, N, s, t, i, x, y;
  15. char str[310];
  16. PINT p, q;
  17.  
  18. scanf("%d %d", &H, &W);
  19.  
  20. for (y = 0; y < H; ++y) {
  21. scanf("%s", str);
  22. q = space2top + 1;
  23. for (x = 0; x < W; ++x, ++q) {
  24. if (str[x] == '0') {
  25. p = q;
  26. s = ++(*p);
  27. t = 1;
  28. while (*p) {
  29. if (*p < s) {
  30. s = *p;
  31. }
  32. ++table[t][s];
  33. ++t;
  34. --p;
  35. }
  36. } else {
  37. *q = 0;
  38. }
  39. }
  40. }
  41.  
  42. for (x = 1; x <= W; ++x) {
  43. p = table[x] + H;
  44. for (y = 1; y < H; ++y) {
  45. --p;
  46. *p += *(p + 1);
  47. }
  48. }
  49.  
  50. scanf("%d", &N);
  51.  
  52. for (i = 0; i < N; ++i) {
  53. scanf("%d %d", &s, &t);
  54. printf("%d\n", table[t][s]);
  55. }
  56.  
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0s 2604KB
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