小H与小Y刚刚参加完UOIP外卡组的初赛,就迫不及待的跑出考场对答案。
“吔,我的答案和你都不一样!”,小Y说道,”我们去找神犇们问答案吧”。
外卡组试卷中共有m道判断题,小H与小Y一共从其他n个神犇那问了答案。之后又从小G那里得知,这n个神犇中有p个考了满分,q个考了零分,其他神犇不为满分或零分。这可让小Y与小H犯了难。你能帮助他们还原出标准答案吗?如有多解则输出字典序最小的那个。无解输出-1。
Description
Input
第一行四个整数n, m, p, q,意义如上描述。
接下来n行,每一行m个字符’N’或’Y’,表示这题这个神犇的答案。
接下来n行,每一行m个字符’N’或’Y’,表示这题这个神犇的答案。
Output
仅一行,一个长度为m的字符串或是-1。
Sample Input
2 2 2 0 YY YY
Sample Output
YY
Data Constraint
30% : n <= 100.
60% : n <= 5000 , m <= 100.
60% : n <= 5000 , m <= 100.
100% : 1 <= n <= 30000 , 1 <= m <= 500. 0 <= p , q 且 p + q <= n.
var
a,b,c,d,e,last,ans,i,j,k,ans1:longint;
v:array[0..30000]of ansistring;
r:array[0..30000]of ansistring;
last1:ansistring;
p:boolean;
procedure ss(l,r:longint);
var
i,j:longint;
mid:ansistring;
begin
i:=l;
j:=r;
mid:=v[(i+j) div 2];
while ido
begin
while v[i]do inc(i);
while v[j]>mid do dec(j);
if i<=j then
begin
v[0]:=v[i];
v[i]:=v[j];
v[j]:=v[0];
inc(i);
dec(j);
end;
end;
if j>l then ss(l,j);
if ithen ss(i,r);
end;
procedure pd;
begin
last:=0;
last1:=v[1];
for e:=1 to a+1 do
begin
if v[e]<>last1 then
begin
if last=d then
begin
inc(ans);
r[ans]:=last1;
end;
last:=1;
last1:=v[e];
end
else
inc(last);
end;
for i:=1 to ans do
begin
P:=true;
for j:=1 to b do
begin
if r[i][j]='N' then r[i][j]:='Y'
else
if r[i][j]='Y' then r[i][j]:='N';
end;
for j:=1 to a do
if r[i]=v[j] then
begin
p:=false;
break;
end;
if p=true then
begin
writeln(r[i]);
halt;
end;
end;
end;
procedure uu(s:ansistring);
var
i:longint;
t:ansistring;
begin
t:='';
for i:=1 to a do
if s=v[i] then
exit;
for j:=1 to b do
begin
if s[j]='N' then t:=t+'Y';
if s[j]='Y' then t:=t+'N';
end;
for i:=1 to a do
if t=v[i] then
exit;
writeln(s);
halt;
end;
procedure hh(s:string);
var
i:longint;
begin
if length(s)=b then
begin
uu(s);
end
else
for i:=1 to 2 do
begin
if i=1 then
hh(s+'N');
if i=2 then
hh(s+'Y');
end;
end;
begin
//assign(input,'1.in');reset(input);
readln(a,b,c,d);
for e:=1 to a do
readln(v[e]);
ss(1,a);
if (c=0)and(d=0) then
begin
hh('');
end;
if c=0 then
begin
pd;
end;
last:=0;
last1:=v[1];
for e:=1 to a+1 do
begin
if v[e]<>last1 then
begin
if last=c then
begin
inc(ans);
r[ans]:=last1;
end;
last:=1;
last1:=v[e];
end
else
inc(last);
end;
for i:=1 to ans do
begin
ans1:=0;
for j:=1 to a do
begin
p:=true;
for k:=1 to b do
begin
if r[i][k]=v[j][k] then
begin
p:=false;
break;
end;
end;
if p=true then
inc(ans1);
end;
if ans1=d then
begin
writeln(r[i]);
halt;
end;
end;
writeln(-1);
close(input);
end.