File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` cpp
2+ #include < bits/stdc++.h>
3+ using namespace std ;
4+
5+ int N;
6+ bitset<131072 > v;
7+ int cnt[17 ]{};
8+
9+ void bck (int state) {
10+ if(v[ state] ) return;
11+ v[ state] .flip();
12+ for(int i=0;i<17;i++) if(!(state & (1<<i))) {
13+ bck(state | (1<<i));
14+ }
15+ }
16+
17+ int main() {
18+ cin.tie(0)->sync_with_stdio(0);
19+
20+ v[131071].flip();
21+
22+ cin>>N;
23+ for(int i=0;i<N;i++) {
24+ string a;
25+ cin>>a;
26+ int state = 0;
27+ for(char c : a) state |= (1<<(c-'a'));
28+ bck(state);
29+ }
30+
31+ string str;
32+ cin>>str;
33+ long long ans = 0;
34+ int state = 0;
35+ for(int i=0,j=-1;i<str.size();i++) {
36+ while(j<(int)str.size()-1 && !v[state]) {
37+ j++;
38+ if(!cnt[str[j]-'a']++) state |= (1<<(str[j]-'a'));
39+ }
40+ if(v[state]) ans += str.size() - j;
41+ if(!--cnt[str[i]-'a']) state ^= (1<<(str[i]-'a'));
42+ }
43+
44+ cout<<ans;
45+
46+ }
47+ ```
You can’t perform that action at this time.
0 commit comments