fork download
  1. /* paiza POH! vol.2
  2.  * result:
  3.  * http://p...content-available-to-author-only...a.jp/poh/paizen/result/e3ca9480c4e8291e039a998a63b586df
  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. if (H == 1 && W == 1) {
  37. String p = in.readLine();
  38. x = Integer.parseInt(in.readLine());
  39. if ("1".equals(p)) {
  40. for (i = 0; i < x; i++) {
  41. output.append("0\n");
  42. }
  43. } else {
  44. for (i = 0; i < x; i++) {
  45. line = in.readLine();
  46. if ("1 1".equals(line)) {
  47. output.append("1\n");
  48. } else {
  49. output.append("0\n");
  50. }
  51. }
  52. }
  53. System.out.print(output);
  54. return;
  55. }
  56.  
  57. for (y = 0; y < H; y++) {
  58. line = in.readLine();
  59. for (x = 0; x < W; x++) {
  60. if (line.charAt(x) == '0') {
  61. space2top[x]++;
  62. s = space2top[x];
  63. t = 1;
  64. for (i = x; i >= 0 && space2top[i] > 0; i--) {
  65. if (space2top[i] < s) {
  66. s = space2top[i];
  67. }
  68. table[t][s]++;
  69. t++;
  70. }
  71. } else {
  72. space2top[x] = 0;
  73. }
  74. }
  75. }
  76.  
  77. for (t = 1; t <= W; t++) {
  78. temp2 = table[t];
  79. for (s = H - 1; s > 0; s--) {
  80. temp2[s] = temp2[s] + temp2[s + 1];
  81. }
  82. }
  83.  
  84. final int N = Integer.parseInt(in.readLine()); // ウィジェット数
  85.  
  86. for (i = 0; i < N; i++)
  87. {
  88. hw = in.readLine().split(" ");
  89. s = Integer.parseInt(hw[0]); // ウィジェットの縦サイズ
  90. t = Integer.parseInt(hw[1]); // ウィジェットの横サイズ
  91.  
  92. output.append(table[t][s]);
  93. output.append('\n');
  94. }
  95.  
  96. System.out.print(output);
  97.  
  98. } // end of main(String[])
  99. }
  100.  
Success #stdin #stdout 0.08s 380224KB
stdin
1 1
1
7
2 2
1 1
3 2
3 2
2 3
3 1
1 3
stdout
0
0
0
0
0
0
0