Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: erng
Problemset: ทางเชื่อม
Language: cpp
Time: 0.336 second
Submitted On: 2026-03-09 21:23:11
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll nx=5005;
ll q, sz, mod=1e9+7;
char mp[2][nx];
ll dp[2][nx];
void solve()
{
cin>>sz;
for (int i=0; i<2; i++)
{
for (int j=1; j<=sz; j++)
{
cin>>mp[i][j];
dp[i][j]=0;
}
}
dp[0][0]=1;
dp[1][0]=1;
for (int i=1; i<=sz; i++)
{
if (mp[0][i]=='.' && mp[1][i]=='.') dp[0][i]=(dp[0][i-1]+dp[1][i-1])%mod, dp[1][i]=dp[0][i];
else if (mp[0][i]=='#' && mp[1][i]=='.') dp[1][i]=dp[1][i-1], dp[0][i]=0;
else if (mp[1][i]=='#' && mp[0][i]=='.') dp[0][i]=dp[0][i-1], dp[1][i]=0;
else dp[0][i]=0, dp[1][i]=0;
}
cout<<(dp[0][sz]+dp[1][sz])%mod<<'\n';
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>q;
for (int i=1; i<=q; i++) solve();
}