-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLuogu_P_1381.cpp
48 lines (48 loc) · 1.17 KB
/
Luogu_P_1381.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
#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
size_t n, m;
cin >> n;
unordered_set<string> mp;
// mp.reserve(n);
while (n--) {
string s;
cin >> s;
mp.insert(s);
}
size_t word_count = 0;
cin >> m;
vector<string> passage(m);
{
unordered_set<string> used;
// mp.reserve(n);
for (vector<string>::reference i : passage) {
cin >> i;
if (mp.count(i) && !used.count(i)) used.insert(i), word_count++;
}
}
cout << word_count << '\n';
size_t l = 0, r = m;
while (l < r) {
size_t mid = (l + r) >> 1;
size_t maxc = 0;
for (vector<string>::iterator it = passage.begin(), jt = it + mid - 1;
jt < passage.end(); it++, jt++) {
unordered_set<string> used;
// used.reserve(n);
size_t find_count = 0;
for (vector<string>::iterator ptr = it; ptr <= jt; ptr++)
if (mp.count(*ptr) && !used.count(*ptr))
used.insert(*ptr), find_count++;
maxc = max(maxc, find_count);
}
if (maxc >= word_count)
r = mid;
else
l = mid + 1;
}
cout << l;
return 0;
}