fork download
  1. /* paiza POH! vol.2
  2.  * result:
  3.  * http://p...content-available-to-author-only...a.jp/poh/paizen/result/71cb5cf948b4b965a7096621e769a02c
  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. int H = Integer.parseInt(hw[0]); // ホーム画面縦の区画数
  17. int W = Integer.parseInt(hw[1]); // ホーム画面横の区画数
  18.  
  19. int[][] home = new int[H][W];
  20.  
  21. for (int y = 0; y < H; y++)
  22. {
  23. String line = in.readLine();
  24. for (int x = 0; x < W; x++)
  25. {
  26. home[y][x] = (char)(line.charAt(x) - '0');
  27. }
  28. }
  29.  
  30. int N = Integer.parseInt(in.readLine()); // ウィジェット数
  31.  
  32. for (int i = 0; i < N; i++)
  33. {
  34. String[] st = in.readLine().split(" ");
  35. int s = Integer.parseInt(st[0]); // ウィジェットの縦サイズ
  36. int t = Integer.parseInt(st[1]); // ウィジェットの横サイズ
  37.  
  38. int count = 0, by = H - s + 1, bx = W - t + 1;
  39.  
  40. for (int y = 0; y < by; y++)
  41. {
  42. for (int x = 0; x < bx; x++)
  43. {
  44. int temp = 0, ey = y + s, ex = x + t;
  45. for (int dy = y; dy < ey; dy++)
  46. {
  47. for (int dx = x; dx < ex; dx++)
  48. {
  49. temp += home[dy][dx];
  50. }
  51. }
  52. if (temp == 0)
  53. {
  54. count++;
  55. }
  56. }
  57. }
  58.  
  59. System.out.println(count);
  60. }
  61.  
  62. } // end of main(String[])
  63. }
  64.  
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