[JSOI2008] Blue Mary's campaign map

Source: Internet
Author: User

Toot Toot

When we see N <= 50, it's fun, violence is done, but the most violent way is O (N7) ... Then add a two-point length to O (N6logn), and then we continue to optimize, the violence compared to the O (1) of the hash value, can reach O (N5logn), to barely enough ... But we can also optimize, the first matrix of all the side length of the sub-matrix of L is stored in an array, and then sort, then we enumerate the second matrix of the sub-matrix, and then in the array with Lower_bound query on the line. The complexity of this should be O (N3log (n2) * Logn).

~ ~ The hash value of a matrix is the sum of the hashes of each row ~ ~

1#include <cstdio>2#include <iostream>3#include <cmath>4#include <algorithm>5#include <cstring>6#include <cstdlib>7#include <cctype>8#include <vector>9#include <stack>Ten#include <queue> One using namespacestd; A #defineEnter puts ("") - #defineSpace Putchar (") - #defineMem (a) memset (a, 0, sizeof (a)) thetypedefLong Longll; -typedef unsignedLong Longull; -typedefDoubledb; - Const intINF =0x3f3f3f3f; + Const intEPS = 1e-8; - Const intMAXN = -; + ConstUllBase=19260817;//Please disregard A inline ll read () at { -ll ans =0; -     Charch = GetChar (), last =' '; -      while(!isdigit (CH)) {last = ch; ch =GetChar ();} -      while(IsDigit (CH)) {ans = ans *Ten+ CH-'0'; CH =GetChar ();} -     if(Last = ='-') ans =-ans; in     returnans; - } toInlinevoidWrite (ll x) + { -     if(X <0) x =-X, Putchar ('-'); the     if(x >=Ten) Write (X/Ten); *Putchar (x%Ten+'0'); $ }Panax Notoginseng  - intN, a[2][MAXN][MAXN]; theUll has[2][MAXN][MAXN]; +Ull F[MAXN], B[MAXN *MAXN]; A intCNT =0; the  +  -Ull Calc (intXintYintLBOOLflag) $ { $ull ret =0; -      for(inti = x; I <= x + L-1; ++i) ret + = Has[flag][i][y + L-1]-Has[flag][i][y-1] *F[l]; -     returnret; the } - BOOLJudgeintx)Wuyi { theCNT =0; -      for(inti =1; I <= N-x +1; ++i) Wu          for(intj =1; J <= N-x +1; ++j) -B[++CNT] = Calc (i, J, X,0); AboutSort (b +1, B + cnt +1); $      for(inti =1; I <= N-x +1; ++i) -          for(intj =1; J <= N-x +1; ++j) -         { -ull ha = Calc (i, J, X,1); A             if(*lower_bound (b +1, b +cnt +1, ha) = = ha)return 1; +         } the     return 0; - } $  the intMain () the { then =read (); the      for(intK =0; K <=1; k++) -          for(inti =1; I <= N; ++i) in              for(intj =1; J <= N; ++J) A[k][i][j] =read (); thef[0] =1; the      for(inti =1; I <= N; ++i) F[i] = f[i-1] *Base; About      for(intK =0; K <=1; ++k) the          for(inti =1; I <= N; ++i) the              for(intj =1; J <= N; ++J) Has[k][i][j] = has[k][i][j-1] *Base+A[k][i][j]; the     intL =1, R =N; +      while(L +1<R) -     { the         intMid = (L + R) >>1;Bayi         if(Judge (mid)) L =mid; the         ElseR = mid-1; the     } -Write (judge (L +1) ? L +1: L);        Enter  -     return 0; the}
View Code

[JSOI2008] Blue Mary's campaign map

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.