Codeforces Round #590 (Div. 3)
Example inputCopy 6 7 2323216 1615124 1 3 4 2 13 24 2 12 34 3 536 345 2 46 54 outputCopy YES YES YES NO YES NO Note The first query from the example is described in the problem statement.
很显然的是直的管只能横着放(无法衔接上下移动的方向接过来的管子)对于拐角管 如果之前是横着运动的 那么现在就得上移或者下移如果之前就是上下移动那么现在只可横着移动now所在类 y所在行 dir前面的方向
#include<bits/stdc++.h>
using namespace std
;
char s
[2][200010];
int main()
{
int tt
;scanf("%d",&tt
);
while(tt
--)
{
int n
;scanf("%d",&n
);
scanf("%s%s",s
[0],s
[1]);
int now
=0,y
=0,dir
=0,f
=0;
while(now
<n
)
{
if(dir
==0)
{
if(s
[y
][now
]=='1'||s
[y
][now
]=='2')
{
now
++;
}else
{
y
=!y
;
dir
=1;
}
}else
{
if(s
[y
][now
]=='2'||s
[y
][now
]=='1')
{
f
=1;
break;
}else
{
dir
=0;
now
++;
}
}
}
if(f
||y
==0) puts("NO");
else puts("YES");
}
}