-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday19.2.cpp
53 lines (45 loc) · 1.17 KB
/
day19.2.cpp
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
#include <cmath>
#include <iostream>
#include <fstream>
#include <queue>
#include <string>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef unsigned long long u64;
int main(int argc, char* argv[]) {
ifstream file(argv[1]);
unordered_set<string> avail;
string line;
getline(file, line);
for (int i = 0;i < line.size();) {
int next = line.find(", ", i);
string design = line.substr(i, next-i);
avail.insert(design);
if (next == string::npos) break;
i = next + 2;
}
u64 res = 0;
getline(file, line); // Empty line
while (getline(file, line)) {
vector<u64> dp(line.size());
for (int i = 0;i < line.size();i++) {
if (i != 0 && dp[i-1] == 0) continue;
for (int len = 1;len <= line.size() - i;len++) {
string part = line.substr(i, len);
if (avail.contains(part)) {
dp[i + len - 1] += i == 0 ? 1 : dp[i-1];
}
}
}
res += dp[line.size()-1];
}
cout << res << endl;
return 0;
}
/*
16016658540
*/