fork(1) download
  1. // paiza POH! vol.2
  2. // result:
  3. // http://p...content-available-to-author-only...a.jp/poh/paizen/result/85b2f2c34976b832709f2a784a83712f
  4. // author: Leonardone @ NEETSDKASU
  5. using System;
  6. using System.Text;
  7.  
  8. public class Test
  9. {
  10. public static void Main()
  11. {
  12. String[] hw = Console.ReadLine().Split(' ');
  13. int h = Int32.Parse(hw[0]);
  14. int w = Int32.Parse(hw[1]);
  15.  
  16. int[,] tb = new int[301, 301];
  17. int[] sp = new int[w];
  18.  
  19. for (int y = 0; y < h; y++)
  20. {
  21. String line = Console.ReadLine();
  22. for (int x = 0; x < w; x++)
  23. {
  24. if (line[x] == '0')
  25. {
  26. sp[x]++;
  27. int s = sp[x];
  28. int t = 1;
  29. for (int i = x; i >= 0 && sp[i] > 0; i--)
  30. {
  31. if (sp[i] < s)
  32. {
  33. s = sp[i];
  34. }
  35. tb[s, t]++;
  36. t++;
  37. }
  38. }
  39. else
  40. {
  41. sp[x] = 0;
  42. }
  43. }
  44. }
  45.  
  46. for (int x = 1; x <= w; x++)
  47. {
  48. for (int y = h - 1; y > 0; y--)
  49. {
  50. tb[y, x] += tb[y + 1, x];
  51. }
  52. }
  53.  
  54. int n = Int32.Parse(Console.ReadLine());
  55. StringBuilder output = new StringBuilder(n * 6);
  56.  
  57. for (int i = 0; i < n; i++)
  58. {
  59. String[] st = Console.ReadLine().Split(' ');
  60. int s = Int32.Parse(st[0]);
  61. int t = Int32.Parse(st[1]);
  62. output.Append(tb[s, t]);
  63. output.AppendLine();
  64. }
  65. Console.WriteLine(output);
  66. }
  67. }
Success #stdin #stdout 0.03s 34376KB
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