Skip to content

Commit f00fbb3

Browse files
authored
Merge pull request #1741 from AlgorithmWithGod/khj20006
[20251226] BOJ / P5 / Clubbing / 권혁준
2 parents 6e6058b + 2c7e8db commit f00fbb3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
```

0 commit comments

Comments
 (0)