Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: hmmm
Problemset: ทางเชื่อม
Language: cpp
Time: 0.343 second
Submitted On: 2026-02-28 22:08:23
#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++){
cin >> c[i][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
.#
..
*/