-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
52 lines (41 loc) · 1 KB
/
Copy pathsol.cpp
File metadata and controls
52 lines (41 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <string>
using namespace std;
unsigned long long MOD = 998244353;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
while (T--)
{
string s;
cin >> s;
unsigned long long prev_answer = 1ull; // empty string
unsigned long long answer = 1ull; // Always one way
for (int i = 1; i < s.length(); ++i)
{
unsigned long long current = 0ll;
if (s[i] == 'a')
{
current += answer;
if (s[i - 1] == 'b')
{
current += prev_answer;
}
}
if (s[i] == 'b')
{
current += answer;
if (s[i - 1] == 'a')
{
current += prev_answer;
}
}
prev_answer = answer;
answer = current % MOD;
}
cout << answer << '\n';
}
}