Submission

Status:

PP------xx

Subtask/Task Score:

20/100

Score: 20

User: hmmm

Problemset: ทางเชื่อม

Language: cpp

Time: 0.124 second

Submitted On: 2026-02-28 22:07:01

#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e3+10;
char c[2][maxn];

const long long mod = 1e9+7;

int main() {
    cin.tie(nullptr)->sync_with_stdio(0);
    int q;
    cin >> q;
     
    while(q--){
        int l;
        cin >> l;
        for(int i=0; i<2; i++){
            string s;
            cin >> s;
            for(int j=0; j<l; j++){
                c[i][j] = s[j];
            }
        }

        long long dp[2][l];
        if(c[0][0] == '.' && c[1][0] == '.') {
            dp[0][0] = 2;
            dp[1][0] = 2;
        }
        else if(c[0][0] == '.' && c[1][0] == '#') {
            dp[0][0] = 1;
            dp[1][0] = 0;
        }
        else if(c[0][0] == '#' && c[1][0] == '.') {
            dp[0][0] = 0;
            dp[1][0] = 1;
        }
        else {
            dp[0][0] = 0;
            dp[1][0] = 0;
        }

        for(int j=1; j<l; j++){
            if(c[0][j] == '.' && c[1][j] == '.') {
                dp[0][j] = (dp[0][j-1]+dp[1][j-1])%mod;
                dp[1][j] = (dp[0][j-1]+dp[1][j-1])%mod;
            }
            else if(c[0][j] == '.' && c[1][j] == '#') {
                dp[0][j] = dp[0][j-1];
                dp[1][j] = 0;
            }
            else if(c[0][j] == '#' && c[1][j] == '.') {
                dp[0][j] = 0;
                dp[1][j] = dp[1][j-1];
            }
            else{
                dp[0][j] = 0;
                dp[1][j] = 0;
            }
        }
        cout << (dp[0][l-1]+dp[1][l-1])%mod << '\n';
    }
}

/*
3
1
.
.
2
..
..
2
.#
..
*/