fork(1) download
  1. /* paiza POH! vol.2
  2.  * result:
  3.  * http://p...content-available-to-author-only...a.jp/poh/paizen/result/1fce29d4f359a04ee55d03b1e0a8d683
  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 long starttime = System.currentTimeMillis();
  13.  
  14. private static final BufferedReader s_in = new BufferedReader(
  15.  
  16. private static final int[][] s_table = new int[301][301];
  17.  
  18. private static final int[] s_space2top = new int[300];
  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.  
  30. int x, y, i, s, t;
  31. int[] temp1, temp2;
  32. String line;
  33.  
  34. String[] hw = in.readLine().split(" ");
  35. final int H = Integer.parseInt(hw[0]); // ホーム画面縦の区画数
  36. final int W = Integer.parseInt(hw[1]); // ホーム画面横の区画数
  37.  
  38.  
  39. for (y = 0; y < H; y++) {
  40. 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. temp2 = table[t];
  61. for (s = H - 1; s > 0; s--) {
  62. temp2[s] = temp2[s] + temp2[s + 1];
  63. }
  64. }
  65.  
  66. final int N = Integer.parseInt(in.readLine()); // ウィジェット数
  67.  
  68. for (i = 0; i < N; i++)
  69. {
  70. hw = in.readLine().split(" ");
  71. s = Integer.parseInt(hw[0]); // ウィジェットの縦サイズ
  72. t = Integer.parseInt(hw[1]); // ウィジェットの横サイズ
  73.  
  74. output.append(table[t][s]);
  75. output.append('\n');
  76. }
  77.  
  78. System.out.print(output);
  79.  
  80.  
  81. long endtime = System.currentTimeMillis();
  82. while (endtime - starttime < 5950) {
  83. endtime = System.currentTimeMillis();
  84. }
  85.  
  86. } // end of main(String[])
  87. }
  88.  
Time limit exceeded #stdin #stdout 5s 380352KB
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