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