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