-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannoyingPaintingTool.cpp
72 lines (64 loc) · 1.75 KB
/
annoyingPaintingTool.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("annoyingPaintingTool.in");
ofstream fout("annoyingPaintingTool.out");
int main()
{
while (true)
{
int n = 0, m = 0, c = 0, r = 0;
fin >> n >> m >> r >> c;
if (n + m + r + c == 0)
{
break;
}
vector<string> a(n);
for (int i = 0; i <= n - 1; ++i)
{
fin >> a[i];
}
int ans = 0;
for (int y0 = 0; y0 <= n - 1 && ans >= 0; ++y0)
{
for (int x0 = 0; x0 <= m - 1 && ans >= 0; ++x0)
{
if (a[y0][x0] == '1')
{
if (y0 + r - 1 > n - 1 || x0 + c - 1 > m - 1)
{
ans = -1;
}
else
{
++ans;
for (int y1 = y0; y1 <= y0 + r - 1; ++y1)
{
for (int x1 = x0; x1 <= x0 + c - 1; ++x1)
{
if (a[y1][x1] == '0')
{
a[y1][x1] = '1';
}
else
{
a[y1][x1] = '0';
}
}
}
}
}
}
}
fout << ans << '\n';
}
return 0;
}