Test instructions: The position of the same square as the maximum Bingchang of the same square matrix in the given character matrix
Write the string hash for the first time, and choose two different modules for a two-dimensional string hash.
Should be judged by the model of equality after the violence sweep matrix to judge, but I see the "Hash in the informatics competition in a class of applications," wrote:
So I'm going to weigh it again? Definitely NOT!!!
So after writing, then tune, call up a few like useless unsigned long long such a brain residue error, handed up on a 233
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;typedef unsigned long Long Ll;const int N = 503;const ll p = 100007;const int p1 = 1007;const int P2 = 10007;struct Node {ll to; int NXT, X, Y;n Ode (ll _to = 0, int _nxt = 0, int _x = 0, int _y = 0): to (_to), NXT (_NXT), X (_x), Y (_y) {}} e[n * N];char s[n][n];int PO Int[p + 3], CNT, N, M;ll Hash1[n][n], hash[n][n], pow1[n], pow2[n];void ins (ll from, ll to, int x, int y) {e[++cnt] = node (To, Point[from], x, y); Point[from] = cnt;} int __ (ll T) {ll f = t% p;for (int i = point[f]; i; i = e[i].nxt) if (e[i].to = = t) return I;return 0;} bool _ (int t) {memset (point, 0, sizeof): cnt = 0;ll num;for (int i = 1; I <= n-t + 1; ++i) for (int j = 1; J < = m-t + 1; ++J) {num = hash[i + t-1][j + t-1]-hash[i + t-1][j-1] * Pow1[t]-hash[i-1][j + t-1] * Pow2[t] + hash[i-1] [J-1] * pow1[t] * POW2[T];IF (__ (NUM)) return 1;ins (num% p, num, I, j);} return 0;} int main () {scanf ("%d%d", &n,&M); for (int i = 1; I <= n; ++i) scanf ("%s", S[i] + 1);p ow1[0] = 1; Pow2[0] = 1;for (int i = 1; i < n; ++i) pow1[i] = pow1[i-1] * P1, pow2[i] = pow2[i-1] * p2;for (int i = 1; I <= N; ++i) for (int j = 1; j <= m; ++j) {hash1[i][j] = hash1[i][j-1] * p1 + (int) s[i][j];hash[i][j] = hash[i-1][j] * p2 + HASH1[I][J];} int left = 0, right = N = = m? n-1: Min (n, m), Mid;while (left < right) {mid = [left + right + 1] >> 1;if (_ (mid)) left = Mid;else right = mi D-1;} if (left = = 0) puts ("0"), else {printf ("%d\n", left), memset (point, 0, sizeof (point)), CNT = 0;for (int i = 1; I <= n-le FT + 1; ++i) for (int j = 1; J <= M-left + 1; ++j) {ll num = hash[i + left-1][j + left-1]-hash[i + left-1][j-1] * POW 1[left]-hash[i-1][j + left-1] * Pow2[left] + hash[i-1][j-1] * Pow1[left] * POW2[LEFT];IF (right = __ (num)) {Prin TF ("%d%d\n%d%d\n", e[right].x, E[right].y, I, j); return 0;} INS (num% p, num, I, j);}} return 0;}
The Magic hash, I've been so confused about your time complexity.
"URAL 1486" Equal squares