fork download
  1. /* paiza POH! vol.2
  2.  * result:
  3.  * http://p...content-available-to-author-only...a.jp/poh/paizen/result/667e0fa5c6f16c59c54cf481415ba617
  4.  * author: Leonardone @ NEETSDKASU
  5.  */
  6. import java.util.*;
  7. import java.lang.*;
  8. import java.io.*;
  9.  
  10. final class Main
  11. {
  12.  
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15.  
  16. final int[][] table = new int[301][301];
  17.  
  18. final int[] space2top = new int[300];
  19.  
  20. final StringBuilder output = new StringBuilder(450000);
  21.  
  22.  
  23. int x, y, i, s, t;
  24. int[] temp1, temp2;
  25. String line;
  26.  
  27. String[] hw = in.readLine().split(" ");
  28. final int H = Integer.parseInt(hw[0]); // ホーム画面縦の区画数
  29. final int W = Integer.parseInt(hw[1]); // ホーム画面横の区画数
  30.  
  31.  
  32. for (y = 0; y < H; y++) {
  33. line = in.readLine();
  34. for (x = 0; x < W; x++) {
  35. if (line.charAt(x) == '0') {
  36. space2top[x]++;
  37. s = space2top[x];
  38. t = 1;
  39. for (i = x; i >= 0 && space2top[i] > 0; i--) {
  40. if (space2top[i] < s) {
  41. s = space2top[i];
  42. }
  43. table[t][s]++;
  44. t++;
  45. }
  46. } else {
  47. space2top[x] = 0;
  48. }
  49. }
  50. }
  51.  
  52. for (t = 1; t <= W; t++) {
  53. temp2 = table[t];
  54. for (s = H - 1; s > 0; s--) {
  55. temp2[s] = temp2[s] + temp2[s + 1];
  56. }
  57. }
  58.  
  59. final int N = Integer.parseInt(in.readLine()); // ウィジェット数
  60.  
  61. for (i = 0; i < N; i++)
  62. {
  63. hw = in.readLine().split(" ");
  64. s = Integer.parseInt(hw[0]); // ウィジェットの縦サイズ
  65. t = Integer.parseInt(hw[1]); // ウィジェットの横サイズ
  66.  
  67. output.append(table[t][s]);
  68. output.append('\n');
  69. }
  70.  
  71. System.out.print(output);
  72.  
  73. } // end of main(String[])
  74. }
  75.  
Success #stdin #stdout 0.08s 380224KB
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