Skip to content

Commit bdf65ef

Browse files
committed
atcoder/abc071D
1 parent fc3eea1 commit bdf65ef

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

atcoder/abc071/D/main.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

0 commit comments

Comments
 (0)