# |
Author |
Problem |
Lang |
Verdict |
Time |
Memory |
Sent |
Judged |
|
61715043 |
Practice:
truesetu |
1234C
- 23
|
C++14 (GCC 6-32)
|
Accepted
|
108 ms
|
6988 KB
|
2019-10-02 15:21:11 |
2019-10-02 15:21:20 |
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define maxi 1e18
#define pll pair<ll,ll>
#define inf 1e18
const ll mod=1e9+7;
map<ll,ll> pos;
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}
int main(){
ll q;
cin>>q;
while(q--){
ll n,i,j,k;
cin>>n;
string s[2];
cin>>s[0]>>s[1];
ll dp[n][2][2];
for(i=n-1;i>=0;i--){
for(j=1;j>=0;j--){
for(k=1;k>=0;k--){
dp[i][j][k]=0;
}
}
}
if(s[1][n-1]-'0'<=2){dp[n-1][0][1]=1;}
else dp[n-1][1][1]=1;
for(i=n-1;i>=0;i--){
for(k=1;k>=0;k--){
for(j=1;j>=0;j--){
if(i==n-1&&j==1)continue;
if(s[j][i]=='1'||s[j][i]=='2'){
//cout<<i<<" "<<j<<" "<<k<<endl;
dp[i][0][j]=dp[i+1][0][j];
}
else{
// cout<<i<<" "<<j<<" "<<k<<endl;
if(k==0){dp[i][k][j]=dp[i][k+1][(j+1)%2];}
else dp[i][k][j]=dp[i+1][k-1][j];
}
}
}
}
//cout<<dp[1][0][0]<<endl;
// cout<<dp[1][1][1]<<endl;
if(dp[0][0][0]==1){
cout<<"YES";
}
else cout<<"NO";
cout<<endl;
}
}
Click to see test details