fork(2) download
  1. /* paiza POH! vol.2
  2.  * result:
  3.  * http://p...content-available-to-author-only...a.jp/poh/paizen/result/a308d7d4760af2a3d5de4783b886145b
  4.  * author: Leonardone @ NEETSDKASU
  5.  */
  6. import java.util.*;
  7. import java.lang.*;
  8. import java.io.*;
  9.  
  10. class Main
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14.  
  15. String[] hw = in.readLine().split(" ");
  16. final int H = Integer.parseInt(hw[0]); // ホーム画面縦の区画数
  17. final int W = Integer.parseInt(hw[1]); // ホーム画面横の区画数
  18.  
  19. int[][] home = new int[H][W];
  20.  
  21. int spacecount = 0;
  22.  
  23. for (int y = 0; y < H; y++)
  24. {
  25. String line = in.readLine();
  26. for (int x = 0; x < W; x++)
  27. {
  28. char ch = line.charAt(x);
  29. home[y][x] = (int)(ch - '0');
  30. if (ch == '0')
  31. {
  32. spacecount++;
  33. }
  34. }
  35. }
  36.  
  37. final int N = Integer.parseInt(in.readLine()); // ウィジェット数
  38.  
  39. for (int i = 0; i < N; i++)
  40. {
  41. String[] st = in.readLine().split(" ");
  42. int s = Integer.parseInt(st[0]); // ウィジェットの縦サイズ
  43. int t = Integer.parseInt(st[1]); // ウィジェットの横サイズ
  44.  
  45. if (s == 1 && t == 1)
  46. {
  47. System.out.println(spacecount);
  48. continue;
  49. }
  50.  
  51. int count = 0;
  52. for (int hy = 0; hy < H; hy++)
  53. {
  54. for (int hx = 0; hx < W; hx++)
  55. {
  56. if (home[hy][hx] != 0)
  57. {
  58. continue;
  59. }
  60. boolean flag = true;
  61. for (int dy = 0; dy < s && flag; dy++)
  62. {
  63. int y = hy + dy;
  64. if (y >= H)
  65. {
  66. flag = false;
  67. break;
  68. }
  69. for (int dx = 0; dx < t && flag; dx++)
  70. {
  71. int x = hx + dx;
  72. if (x >= W)
  73. {
  74. flag = false;
  75. break;
  76. }
  77. if (home[y][x] != 0)
  78. {
  79. flag = false;
  80. }
  81. }
  82. }
  83. if (flag == true)
  84. {
  85. count++;
  86. }
  87. }
  88. }
  89. System.out.println(count);
  90. }
  91.  
  92. } // end of main(String[])
  93.  
  94. }
  95.  
Success #stdin #stdout 0.07s 380224KB
stdin
5 5
00000
00100
00010
10001
10000
3
2 2
1 1
3 2
stdout
6
20
2