Submission

Status:

PP--------

Subtask/Task Score:

20/100

Score: 20

User: erng

Problemset: ทางเชื่อม

Language: cpp

Time: 0.361 second

Submitted On: 2026-03-09 20:55:15

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll nx=5005;
ll q, sz, mod=1000000007;
char mp[3][nx];
int dp[3][nx];

void solve()
{
    cin>>sz;
    for (int i=1; i<=2; i++)
    {
        for (int j=1; j<=sz; j++)
        {
            cin>>mp[i][j];
            dp[i][j]=0;
        }
    }
    for (int i=1; i<=sz; i++)
    {
        if (mp[1][i]=='#' && mp[2][i]=='#')
        {
            cout<<0;
            return;
        }
    }
    dp[1][0]=1;
    dp[2][0]=1;
    for (int i=1; i<=sz; i++)
    {
        if (mp[1][i]=='#') dp[1][i]=0;
        if (mp[2][i]=='#') dp[2][i]=0;
        if (mp[1][i]=='.' && mp[2][i]=='.') dp[1][i]=(dp[1][i-1]+dp[2][i-1])%mod, dp[2][i]=dp[1][i];
        else if (mp[1][i]=='#') dp[2][i]=dp[2][i-1];
        else dp[1][i]=dp[1][i-1];
    }
    cout<<(dp[1][sz]+dp[2][sz])%mod<<'\n';
}


int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>q;
    for (int i=1; i<=q; i++) solve();
}