Pagini recente » Cod sursa (job #2499577) | Cod sursa (job #2453073) | Cod sursa (job #1809706) | Cod sursa (job #2908858) | Cod sursa (job #3254261)
//https://infoarena.ro/problema/strmatch 40p (92p) V:I sa pun sirul de referinta
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("fast-math")
//#pragma GCC optimize ("unroll-loops")
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
vector <int> rez;
int d[4000005], ult, cnt;
void adaugRez(const int& i, const int& asz)//adaug la rezultat daca e cazul
{
if (d[i] == d[0])
{
++cnt;
if (cnt <= 1000)
{
ult = i;
rez.push_back(i - asz - 1);
}
}
}
void verifEgale(const int& ij, const int& ik, const int& i, const int& asz, const string& c)//vad cate sunt egale
{
int j, k;
j = ij;
k = ik;
if (ult)
{
//cout << (i - ult) << " ";
if ((i - ult) < d[0])
{
d[i] = d[i - ult];
j = j + d[i];
k = k + d[i];
}
}
//cout << i << " " << j << " " << k << " " << d[i] << " ";
while ((j < (int)c.size()) && (c[j] == c[k]))
{
++d[i];
++j;
++k;
}
//cout << d[i] << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
//cin.tie(NULL);
string a, b, c;
int i;
fin >> a;
fin >> b;
c = a + "#" + b;
//cout << c;
i = 1;
d[0] = (int)a.size();
while (c[i] != '#')
{
verifEgale(i, 0, i, (int)a.size(), c);
++i;
}
++i;
while (i < (int)c.size())
{
verifEgale(i, 0, i, (int)a.size(), c);
adaugRez(i, (int)a.size());
//cout << ult << "\n";
++i;
}
/*for (i = 0; i < c.size(); ++i)
{
cout << d[i] << " ";
}*/
fout << cnt << "\n";
for (auto x : rez)
{
fout << x << " ";
}
return 0;
}