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