include iostream include vector include string include algorithm using

 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
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int n, m, q;
cin >> n >> m >> q;
vector< vector<bool> > map(n + 1, vector<bool>(m + 1, false));
string a, b;
cin >> a >> b;
for (int i = 0; i <= max(n, m); ++i)
{
if (i < a.size() && a[i] == '1')
map[i][0] = true;
if (i < b.size() && b[i] == '1')
map[0][i] = true;
}
for (int i = 1; i <= min(6, n); ++i)
{
for (int j = 1; j <= min(6, m); ++j)
{
map[i][j] = !(map[i - 1][j] && map[i][j - 1]);
}
}
for (int i = 5; i <= n; ++i)
map[i][1] = !(map[i - 1][1] && map[i][0]);
for (int j = 5; j <= m; ++j)
map[1][j] = !(map[1][j - 1] && map[0][j]);
for (int i = 0; i < q; ++i)
{
int w, e;
cin >> w >> e;
if (w < 5 && e < 5)
if (map[w][e])
cout << "Yes" << endl;
else
cout << "No" << endl;
else
{
if (map[w - e + 1][1])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
return 0;
}