Skip to content

Commit 091c92b

Browse files
committed
Wildcard pattern matching test
1 parent 4c7dc3b commit 091c92b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

verify/poly/wildcard.test.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// @brief Wildcard Pattern Matching
2+
#define PROBLEM "https://judge.yosupo.jp/problem/wildcard_pattern_matching"
3+
#pragma GCC optimize("Ofast,unroll-loops")
4+
#pragma GCC target("avx2,tune=native")
5+
#include "cp-algo/algebra/poly.hpp"
6+
#include <bits/stdc++.h>
7+
8+
using namespace std;
9+
using namespace cp_algo::algebra;
10+
11+
const int mod = 1e9 + 9;
12+
13+
using base = modint<mod>;
14+
using polyn = poly_t<base>;
15+
16+
void solve() {
17+
string ST[2];
18+
cin >> ST[0] >> ST[1];
19+
polyn P[2][3];
20+
for(int i: {0, 1}) {
21+
for(int j: {1, 2, 3}) {
22+
vector<base> coeffs(size(ST[i]));
23+
for(size_t k = 0; k < size(ST[i]); k++) {
24+
coeffs[k] = bpow(base(ST[i][k] == '*' ? 0 : ST[i][k] - 'a' + 1), j);
25+
}
26+
P[i][j-1] = coeffs;
27+
}
28+
}
29+
auto dist = polyn::semicorr(P[0][0], P[1][2])
30+
+ polyn::semicorr(P[0][2], P[1][0])
31+
- 2*polyn::semicorr(P[0][1], P[1][1]);
32+
string ans(size(ST[0]) - size(ST[1]) + 1, '0');
33+
for(size_t j = 0; j <= size(ans); j++) {
34+
ans[j] = '0' + int(dist[j] == 0);
35+
}
36+
cout << ans << "\n";
37+
}
38+
39+
signed main() {
40+
//freopen("input.txt", "r", stdin);
41+
ios::sync_with_stdio(0);
42+
cin.tie(0);
43+
int t = 1;
44+
//cin >> t;
45+
while(t--) {
46+
solve();
47+
}
48+
}

0 commit comments

Comments
 (0)