fork download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <cmath>
  14. #include <iomanip>
  15. #define dibs reserve
  16. #define OVER9000 1234567890
  17. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  18. #define tisic 47
  19. #define soclose 1e-8
  20. #define chocolate win
  21. // so much chocolate
  22. #define patkan 9
  23. #define ff first
  24. #define ss second
  25. #define abs(x) ((x < 0)?-(x):x)
  26. #define uint unsigned int
  27. #define dbl long double
  28. using namespace std;
  29. // mylittledoge
  30.  
  31. int main() {
  32. cin.sync_with_stdio(0);
  33. cin.tie(0);
  34. int T;
  35. cin >> T;
  36. for(int t =0; t < T; t++) {
  37. int N,M;
  38. cin >> N >> M;
  39. vector< vector<int> > A(N,vector<int>(M));
  40. for(int i =0; i < N; i++)
  41. for(int j =0; j < M; j++) cin >> A[i][j];
  42.  
  43. int ans =min(N,2)*min(M,2);
  44. vector<int> H0(M,0),H(M,0); // vyska obdlznika sirky 1,3
  45. for(int i =0; i < N; i++) {
  46. stack< pair<int,int> > S; // sirka aspon 3
  47. for(int j =0; j < M; j++) {
  48. H0[j]++;
  49. if(i > 1 && A[i][j]-A[i-1][j] != A[i-1][j]-A[i-2][j]) H0[j] =2;
  50. ans =max(ans,H0[j]);
  51. if(j > 0) ans =max(ans,min(H0[j],H0[j-1])*2);
  52. H[j]++;
  53. H[j] =min(H[j],H0[j]);
  54. if(j > 0) H[j] =min(H[j],H0[j-1]);
  55. if(j > 1) H[j] =min(H[j],H0[j-2]);
  56. if(j > 1 && A[i][j]-A[i][j-1] != A[i][j-1]-A[i][j-2]) H[j] =0;
  57.  
  58. if(j <= 1) continue;
  59. // pridam panel napravo, co nepasuje?
  60. int x =j-2;
  61. while(!S.empty() && S.top().ff > H[j]) {
  62. ans =max(ans,(j-S.top().ss)*S.top().ff);
  63. x =S.top().ss;
  64. S.pop();}
  65.  
  66. if(S.empty() || S.top().ff != H[j]) if(H[j] > 0) S.push(make_pair(H[j],x));}
  67.  
  68. while(!S.empty()) {
  69. ans =max(ans,(M-S.top().ss)*S.top().ff);
  70. S.pop();}
  71. }
  72.  
  73. cout << ans << "\n";}
  74. return 0;}
  75.  
  76. // look at my code
  77. // my code is amazing
Success #stdin #stdout 0s 3480KB
stdin
Standard input is empty
stdout
Standard output is empty