Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iomanip>
- using namespace std;
- ifstream fin("maria.in");
- ofstream fout("maria.out");
- int n, m, p, q;
- int k;
- int a[1001][1001];
- int sum[1001][1001];
- int cautaLocuri(int p, int q)
- {
- int locuri = 0;
- int s;
- int x1, y1, x2, y2;
- for (int i = 1; i <= n - p + 1; ++i)
- {
- for (int j = 1; j <= m - q + 1; ++j)
- {
- x1 = i;
- y1 = j;
- x2 = i + p - 1;
- y2 = j + q - 1;
- s = sum[x2][y2] - sum[x2][y1 - 1] - sum[x1 - 1][y2] + sum[x1 - 1][y1 - 1];
- if (s == 0)
- ++locuri;
- }
- }
- return locuri;
- }
- int main()
- {
- fin >> n >> m >> p >> q;
- fin >> k;
- int x, y;
- for (int i = 1; i <= k; ++i)
- {
- fin >> x >> y;
- a[x][y] = 1;
- }
- for (int i = 1; i <= n; ++i)
- {
- for (int j = 1; j <= m; ++j)
- {
- sum[i][j] = a[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
- }
- }
- int cnt = 0;
- cnt += cautaLocuri(p, q);
- cnt += cautaLocuri(q, p);
- fout << cnt;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement