-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay7.cpp
More file actions
93 lines (84 loc) · 2.17 KB
/
Day7.cpp
File metadata and controls
93 lines (84 loc) · 2.17 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <bits/stdc++.h>
#define int long long
#define allr(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define ld long double
#define INF (int)(1e18)
#define MOD 1000000007
using namespace std;
vector<string> v;
void Part1() {
string s;
while (cin >> s && s != "*") {
v.push_back(s);
}
int n = v.size(), m = v[0].size();
int cnt = 0;
vector<bool> split(n + 1, false);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (v[i][j] == 'S') {
split[j] = true;
if (v[i + 1][j] != '^')
v[i + 1][j] = '|';
} else {
if (v[i][j] == '^' && split[j] == true) {
split[j] = false;
if (j + 1 < m) {
split[j + 1] = true;
v[i][j + 1] = '|';
}
if (j - 1 >= 0) {
split[j - 1] = true;
v[i][j - 1] = '|';
}
cnt++;
}
}
}
}
cout << cnt << "\n";
}
void Part2() {
int n = v.size(), m = v[0].size();
vector<vector<int> > memo(n + 1, vector<int>(m + 1, 0));
for (int i = 0; i < m; i++) {
if (v[0][i] == 'S') {
memo[0][i] = 1;
break;
}
}
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < m; j++) {
if (v[i][j] != '^') {
memo[i + 1][j] += memo[i][j];
} else {
if (j - 1 >= 0) {
memo[i + 1][j - 1] += memo[i][j];
}
if (j + 1 < m) {
memo[i + 1][j + 1] += memo[i][j];
}
}
}
}
int ans = 0;
for (int i = 0; i < m; i++) {
ans += memo[n - 1][i];
}
cout << ans << "\n";
v.clear();
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("promote.in","r",stdin);
// freopen("promote.out","w",stdout);
int tests = 1;
// cin >> tests;
while (tests--) {
Part1();
Part2();
}
}