Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: devilpoohs

Problemset: ทางเชื่อม

Language: cpp

Time: 0.359 second

Submitted On: 2026-03-09 16:48:44

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
char ch[2][5005];
int dp[2][5005];
void sol(){
    int n;
    cin>>n;

    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin>>ch[i][j];
        }
    }
    ch[0][n]='.';
    ch[1][n]='.';
    memset(dp,0,sizeof(dp));
	if(ch[0][0]!='#') dp[0][0]=1;
	if(ch[1][0]!='#') dp[1][0]=1;
	for(int j=1;j<=n;j++){
		if(ch[0][j-1]!='#' and ch[0][j]!='#')
			dp[0][j]=dp[0][j-1]+dp[1][j-1];
		dp[0][j]%=mod;
		if(ch[1][j-1]!='#' and ch[1][j]!='#')
			dp[1][j]=dp[0][j-1]+dp[1][j-1];
		dp[1][j]%=mod;
	}
	cout<< (dp[0][n]+dp[1][n])%mod<<'\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        sol();
    }
}
/*
3
4
.#..
.#..
4
.#..
...#
2
#.
..

*/