2022-01-24 12:41:50 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using std::cin;
|
|
|
|
using std::cout;
|
2022-10-28 09:27:23 +00:00
|
|
|
const char endl = '\n';
|
2022-01-24 12:41:50 +00:00
|
|
|
|
2022-10-28 09:27:23 +00:00
|
|
|
const int N = 1e6 + 5;
|
2022-01-25 01:28:09 +00:00
|
|
|
|
2022-10-28 09:27:23 +00:00
|
|
|
int next[N], f[N];
|
2022-01-24 12:41:50 +00:00
|
|
|
std::string s1, s2;
|
|
|
|
|
|
|
|
int main() {
|
2022-10-28 09:27:23 +00:00
|
|
|
std::ios::sync_with_stdio(false);
|
|
|
|
cin.tie(nullptr);
|
|
|
|
|
2022-01-24 12:41:50 +00:00
|
|
|
cin >> s1 >> s2;
|
2022-10-28 09:27:23 +00:00
|
|
|
|
2022-01-25 01:28:09 +00:00
|
|
|
next[0] = -1;
|
2022-10-28 09:27:23 +00:00
|
|
|
|
2022-01-25 01:28:09 +00:00
|
|
|
for (int i = 1, j = -1; i < s2.size(); i++) {
|
2022-10-28 09:27:23 +00:00
|
|
|
while (~j && s2[i] != s2[j + 1]) j = next[j];
|
2022-01-25 01:28:09 +00:00
|
|
|
if (s2[i] == s2[j + 1]) j++;
|
|
|
|
next[i] = j;
|
|
|
|
}
|
2022-10-28 09:27:23 +00:00
|
|
|
|
2022-01-25 01:28:09 +00:00
|
|
|
for (int i = 0, j = -1; i < s1.size(); i++) {
|
2022-10-28 09:27:23 +00:00
|
|
|
while (~j && (j == s2.size() || s1[i] != s2[j + 1])) j = next[j];
|
2022-01-25 01:28:09 +00:00
|
|
|
if (s1[i] == s2[j + 1]) j++;
|
2022-10-28 09:27:23 +00:00
|
|
|
if (j + 1 == s2.size()) {
|
2022-01-25 01:28:09 +00:00
|
|
|
cout << i - j + 1 << endl;
|
|
|
|
f[i] = j;
|
2022-01-24 12:41:50 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-28 09:27:23 +00:00
|
|
|
|
2022-01-24 12:41:50 +00:00
|
|
|
for (int i = 0; i < s2.size(); i++) {
|
2022-01-25 01:28:09 +00:00
|
|
|
cout << next[i] + 1 << ' ';
|
2022-01-24 12:41:50 +00:00
|
|
|
}
|
2022-10-28 09:27:23 +00:00
|
|
|
|
2022-01-24 12:41:50 +00:00
|
|
|
cout << endl;
|
2022-10-28 09:27:23 +00:00
|
|
|
|
2022-01-24 12:41:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|