File tree 1 file changed +54
-0
lines changed
1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ using ll = long long ;
5
+
6
+ ll MOD = 1000000007 ;
7
+
8
+ int N;
9
+ vector<string> S (2 );
10
+
11
+ ll solve () {
12
+ vector<ll> DP (N, 0 );
13
+ for (int x = 0 ; x < N; ++x) {
14
+ if (S[0 ][x] == S[1 ][x]) {
15
+ if (x == 0 ) {
16
+ // |
17
+ DP[x] = 3 ;
18
+ } else if (S[0 ][x-1 ] == S[1 ][x-1 ]) {
19
+ // ||
20
+ DP[x] = DP[x-1 ] * 2 % MOD;
21
+ } else {
22
+ // =|
23
+ DP[x] = DP[x-1 ];
24
+ }
25
+ } else if (x > 0 && S[0 ][x] == S[0 ][x-1 ]) {
26
+ // =
27
+ DP[x] = DP[x-1 ];
28
+ } else {
29
+ if (x == 0 ) {
30
+ // =
31
+ DP[x] = 6 ;
32
+ } else if (S[0 ][x-1 ] == S[1 ][x-1 ]) {
33
+ // |=
34
+ DP[x] = DP[x-1 ] * 2 % MOD;
35
+ } else {
36
+ // ==
37
+ DP[x] = DP[x-1 ] * 3 % MOD;
38
+ }
39
+ }
40
+ }
41
+ return DP[N-1 ];
42
+ }
43
+
44
+
45
+ int main () {
46
+ ios_base::sync_with_stdio (false );
47
+ cin.tie (0 ); cout.tie (0 );
48
+
49
+ cin >> N;
50
+ cin >> S[0 ] >> S[1 ];
51
+ cout << solve () << endl;
52
+
53
+ return 0 ;
54
+ }
You can’t perform that action at this time.
0 commit comments