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