Pagini recente » Cod sursa (job #2604970) | Cod sursa (job #2465531) | Cod sursa (job #3278342) | Cod sursa (job #3278190) | Cod sursa (job #3278307)
#include <bits/stdc++.h>
using namespace std;
ifstream fcin(".in");
ofstream fcout(".out");
const int N = 1e3 + 5;
const int baza = 16661;
const int mod = 1e9 + 7;
int v[N][N], h1[N], h2[N];
int n, m;
int fexp(int b, int e)
{
if (e == 0)
return 1;
int r = fexp(b, e / 2);
if (e % 2 == 0)
return 1ll * r * r % mod;
else
return 1ll * r * r % mod * b % mod;
}
int main()
{
fcin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
fcin >> v[i][j];
for (int j1 = 1; j1 < m; j1++)
{
for (int i = 1; i <= n; i++)
{
h1[i] = v[i][j1];
h2[i] = v[i][j1 + 2];
}
int l = 0;
for (int j2 = j1 + 2, p = 1; j2 <= m; j2 += 2, p++)
{
for (int i = 1; i <= n; i++)
if (h1[i] == h2[i])
l++;
else
l = 0;
for (int i = 1; i <= n; i++)
{
h1[i] = (h1[i] + 1ll * fexp(baza, p) * v[i][p + j1]) % mod;
h2[i] = ((h2[i] - 1ll * v[i][p + j1 + 1] * fexp(baza, p)) % mod +
(1ll * baza * v[i][j2]) % mod) % mod;
}
}
}
return 0;
}