define _CRT_SECURE_NO_WARNI NGS include iostream include cstdio includ

  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
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cassert>
#define inf 1e14
#define eps 1e-8
#define EPS 1e-4
using namespace std;
int n, m;
vector <vector <char> > a, b;
vector <vector <int> > g;
void build(int i) {
for (int k = 0; k < n; ++k) {
bool flag(false);
for (int j = 0; j < m; ++j) {
if (a[k][j] != b[i][j] && a[k][j] != '?') {
flag = true;
break;
}
}
if (!flag)
g[i].push_back(k);
}
}
vector <int> used;
vector <int> mt;
bool try_kuhn(int v)
{
if (used[v])
return false;
used[v] = 1;
for (int i = 0; i < g[v].size(); ++i)
{
int to = g[v][i];
if (mt[to] == -1 || try_kuhn(mt[to]))
{
mt[to] = v;
return true;
}
}
return false;
}
int main() {
//freopen("input.txt", "r", stdin);
freopen("lots.in", "r", stdin);
freopen("lots.out", "w", stdout);
while (true)
{
scanf("%d %d\n", &n, &m);
if (!n)
{
return 0;
}
g.clear();
a.assign(n, vector <char>(m));
b.assign(n, vector <char>(m));
g.resize(n);
for (int i = 0; i < n; ++i){
for (int j = 0; j < m; ++j)
scanf("%c", &a[i][j]);
scanf("\n");
}
scanf("\n");
for (int i = 0; i < n; ++i){
for (int j = 0; j < m; ++j)
scanf("%c", &b[i][j]);
scanf("\n");
}
int w(0);
bool flag(false);
for (int j = 0; j < m; ++j)
if (b[0][j] == 'x')
w++;
for (int i = 1; i < n; ++i) {
int w0(0);
for (int j = 0; j < m; ++j)
if (b[i][j] == 'x')
w0++;
if (w0 > w)
flag = true;
else
w = w0;
}
if (flag) {
printf("NO\n");
continue;
}
for (int i = 0; i < n; ++i)
build(i);
mt.assign(n, -1);
/*for (int i = 0; i < n; ++i)
{
for (int j = 0; j < g[i].size(); ++j)
{
if (mt[g[i][j]] == -1)
{
mt[g[i][j]] = i;
break;
}
}
}*/
for (int i = 0; i < n; ++i)
{
used.assign(n, false);
try_kuhn(i);
}
bool f = 1;
for (int i = 0; i < n; ++i)
{
if (mt[i] == -1)
{
printf("NO\n");
f = 0;
break;
}
}
if (f)
{
printf("YES\n");
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
printf("%c", b[mt[i]][j]);
}
printf("\n");
}
}
}
return 0;
}