Submission

Status:

PP--------

Subtask/Task Score:

20/100

Score: 20

User: Seng

Problemset: ทางเชื่อม

Language: cpp

Time: 0.347 second

Submitted On: 2026-05-16 10:59:04

#include <bits/stdc++.h>
using namespace std;
#define seng_code ios::sync_with_stdio(0);cin.tie(0);
char arr[7][5005];
long long dp[7][5005];
const int M = 1e9+7;

int main(){
    seng_code
    int m;cin >> m; 
    while(m--){
        int n;cin >> n;
        int ans = 0;
        memset(dp, sizeof(dp), 0);
        for(int i = 1; i <= 2; i++){
            for(int j = 1; j <= n; j++){
                char x;cin >> x;
                arr[i][j] = x;
            }
        }
        dp[1][0] = dp[2][0] = 1;
        for(int j = 1; j <= n; j++){
            if(arr[1][j] == '#' && arr[2][j] == '.'){
                dp[1][j] = 0;
                dp[2][j] = (dp[2][j-1]%M);
            }
            else if(arr[1][j] == '.' && arr[2][j] == '#'){
                dp[1][j] = (dp[1][j-1]%M);
                dp[2][j] = 0;
            }
            else if(arr[1][j] == '#' && arr[2][j] == '#'){
                dp[1][j] = dp[2][j] = 0;
            }
            else{
                dp[1][j] = dp[2][j] = (dp[1][j-1]+dp[2][j-1])%M;
            }
        }
        cout << (dp[1][n]+dp[2][n])%M << '\n';
    }
}