Pagini recente »
adunare
|
Istoria paginii runda/infogim_2017_runda3_5_8/clasament
|
Istoria paginii runda/lervs_11-12_2024
|
Rating Moise Alexandru (moise_alexandru)
|
Cod sursă (job #474292)
Cod sursă (job
#474292)
#include <fstream>
#include <string>
using namespace std;
ifstream in("fotografie.in");
ofstream out("fotografie.out");
int n, m, p, q;
char first[1005][1005], second[1005][1005];
const unsigned int MOD = 1000000007;
const unsigned int base = 31;
long long hash1[1005][1005], hash2[1005];
int main()
{
in >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
in >> first[i][j];
in >> p >> q;
long long put = 1;
for(int i = 1; i <= q; i++)
put *= base;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= q; j++)
hash1[i][j] = (hash1[i][j-1] * base + (first[i][j] - 'a')) % MOD;
for(int j = q+1; j <= m; j++)
{
hash1[i][j] = ((hash1[i][j-1] * base + (first[i][j] - 'a')) % MOD - put * (first[i][j-q] - 'a')) % MOD;
if(hash1[i][j] < 0)
hash1[i][j] += MOD;
}
}
for(int i = 1; i <= p; i++)
{
for(int j = 1; j <= q; j++)
{
in >> second[i][j];
hash2[i] = (hash2[i] * base + (second[i][j] - 'a')) % MOD;
}
}
for(int i = 1; i <= n - p + 1; i++)
{
for(int j = q; j <= m; j++)
{
int posi = i;
while(posi - i + 1 <= p && hash1[posi][j] == hash2[posi-i+1])
posi++;
if(posi - i + 1 > p)
out << i - 1 << ' ' << j - q << '\n';
}
}
return 0;
}