Submission

Status:

----------

Subtask/Task Score:

0/100

Score: 0

User: Ecir

Problemset: ทางเชื่อม

Language: cpp

Time: 0.428 second

Submitted On: 2025-10-02 18:42:39

#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
const ll modd=1e9+7;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int n;cin >> n;
    while(n--){
        int nn;cin >> nn;
        vector<vector<ll>> dp(3,vector<ll>(nn+9,0));
        vector<vector<bool>> b(3,vector<bool>(nn+9,0));
        dp[1][0]=1;
        dp[2][0]=1;
        for(int i=1;i<=2;i++){
            for(int j=1;j<=nn;j++){
                char c;cin >> c;
                if(c!='.') b[i][j]=1;
            }
        }
        for(int j=1;j<=nn;j++){
            if(b[1][j]==1 && b[2][j]==1) break;
            else if(b[1][j]==1) {
                dp[2][j]+=dp[2][j-1];dp[2][j]%=modd;
            }
            else if(b[2][j]==1) {
                dp[1][j]+=dp[1][j-1];dp[1][j]%=modd;
            }
            else{
                dp[1][j]+=dp[1][j-1]+dp[2][j-1];dp[1][j]%=modd;
                dp[2][j]+=dp[1][j-1]+dp[2][j-1];dp[2][j]%=modd;
            }

        }
        
        cout << dp[1][nn]+dp[2][nn] << '\n';
    }
    return 0;
}
// #include <bits/stdc++.h>
// using namespace std;
// #define f first;
// #define s second;
// int dig[5009];
// char arr[5009][3][5009];
// int main(){
//     ios::sync_with_stdio(0);cin.tie(0);
//     int n;cin >> n;
//     for(int k=1;k<=n;k++){
//         cin >> dig[k];
//         for(int i=1;i<=2;i++){
//             for(int j=1;j<=dig[k];j++) cin >> arr[k][i][j];
//         }
//     }
//     for(int k=1;k<=n;k++){
//         vector<vector<int>> dp(3,vector<int>(5009,0));
//         dp[1][0]=1;
//         dp[2][0]=1;
//         for(int j=1;j<=dig[k];j++){
//             if(dp[1][j]==-1 && dp[2][j]==-1) break;
//             else if(dp[1][j]==-1) dp[2][j]+=dp[2][j-1];
//             else if(dp[2][j]==-1) dp[1][j]+=dp[1][j-1];
//             else{
//                 dp[1][j]+=dp[1][j-1]+dp[2][j-1];
//                 dp[2][j]+=dp[1][j-1]+dp[2][j-1];
//             }
    
//         }
//         cout << dp[1][dig[k]]+dp[2][dig[k]] << '\n';
//     }


//     return 0;
// }