fork(1) download
  1. /* paiza POH! vol.2
  2.  * result:
  3.  * http://p...content-available-to-author-only...a.jp/poh/paizen/result/b2c123936430c16408b83c486e98c6cf
  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, j, x, y;
  15. char str[310];
  16. PINT p, q, r;
  17.  
  18. scanf("%d %d", &H, &W);
  19.  
  20. r = space2top + 1;
  21. for (y = 0; y < H; ++y) {
  22. scanf("%s", str);
  23. q = r;
  24. for (x = 0; x < W; ++x, ++q) {
  25. if (str[x] == '0') {
  26. p = q;
  27. s = ++(*p);
  28. t = 1;
  29. while (*p) {
  30. if (*p < s) {
  31. s = *p;
  32. }
  33. ++table[t][s];
  34. ++t;
  35. --p;
  36. }
  37. } else {
  38. *q = 0;
  39. }
  40. }
  41. }
  42.  
  43. for (x = 1; x <= W; ++x) {
  44. p = q = &table[x][H];
  45. for (y = 1; y < H; ++y) {
  46. --p;
  47. *p += *q;
  48. --q;
  49. }
  50. }
  51.  
  52. scanf("%d", &N);
  53.  
  54. for (i = 0; i < N; ++i) {
  55. scanf("%d %d", &s, &t);
  56. printf("%d\n", table[t][s]);
  57. }
  58.  
  59. return 0;
  60. }
  61.  
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