-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaxwidth.cpp
54 lines (41 loc) · 885 Bytes
/
maxwidth.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
54
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
ll n, m;
int main() {
cin >> n >> m;
vector<char> _long(n);
for(int i = 0; i < n; i++) {
cin >> _long[i];
}
vector<char> _short(m);
for(int i = 0; i < m; i++) {
cin >> _short[i];
}
vector<int> first(m);
vector<int> last(m);
int lp = 0;
for (int i = 0; i < m; i++) {
while(_short[i] != _long[lp]) {
lp++;
}
first[i] = lp;
lp++;
}
int rp = n - 1;
for (int i = m - 1; i >= 0; i--) {
while (_short[i] != _long[rp]) {
rp--;
}
last[i] = rp;
rp--;
}
int best = 0;
for (int i = 1; i < m; i++) {
best = max(best, last[i] - first[i - 1]);
}
cout << best << endl;
return 0;
}