Submission

Status:
---x--x-xx

Score: 0

User: SnowAveNode

Problemset: ทางเชื่อม

Language: cpp

Time: 0.091 second

Submitted On: 2025-04-01 08:19:46

#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0) -> sync_with_stdio(false);
    int t; cin >> t;
    while(t--) {
        int l; cin >> l;
        string top, bottom; cin >> top >> bottom;

        long long dpT = 0, dpB = 0;
        if(top[0] == '.' && bottom[0] == '.') {dpT = 2; dpB = 2;}
        else if(top[0] == '.' && bottom[0] == '#') {dpT = 1; dpB = 0;}
        else if(top[0] == '#' && bottom[0] == '.') {dpT = 0; dpB = 1;}
        else dpT = dpB = 0;
        
        for(int j = 1; j < l; j++) {
            long long newT = 0, newB = 0;
            char ct = top[j], cb = bottom[j];
            if(ct == '.' && cb == '.') {
                long long sum = (dpT + dpB) % 1000000007;
                newT = sum; newB = sum;
            }
            else if(ct == '.' && cb == '#') {
                newT = dpT; newB = 0;
            }
            else if(ct == '#' && cb == '.') {
                newB = dpB; newT = 0;
            }
            else {
                newT = newB = 0;
            }
            dpT = newT & 1000000007;
            dpB = newB % 1000000007;
        }
        long long ans = (dpT + dpB) % 1000000007;
        cout << ans << endl;
    }
}