fork(1) download
  1. // Name:- Transievers
  2.  
  3. // Problem:- Blurry vision
  4.  
  5. // Link:- https://i...content-available-to-author-only...k.com/contests/amrita13/challenges/blurry-vision
  6.  
  7. // Site:- HackerRank
  8.  
  9.  
  10.  
  11. //header files
  12. #include<iostream>
  13. #include<map>
  14. #include<vector>
  15. #include<cstdio>
  16. #include<cmath>
  17. #include<cstring>
  18. using namespace std;
  19. //end of header files
  20.  
  21.  
  22. //definitions
  23.  
  24. #define MOD 1000000007
  25. #define llu long long unsigned
  26. #define lld long long
  27. #define ld long
  28.  
  29. //end of definitions
  30.  
  31.  
  32. //fast input
  33.  
  34. int scan_d() {int ip=getchar_unlocked(),ret=0,flag=1;for(;ip<'0'||ip>'9';ip=getchar_unlocked())if(ip=='-'){flag=-1;ip=getchar_unlocked();break;}for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return flag*ret;}
  35. ld scan_ld() {int ip=getchar_unlocked(),flag=1;ld ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked())if(ip=='-'){flag=-1;ip=getchar_unlocked();break;}for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return flag*ret;}
  36. lld scan_lld() {int ip=getchar_unlocked(),flag=1;lld ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked())if(ip=='-'){flag=-1;ip=getchar_unlocked();break;}for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return flag*ret;}
  37. llu scan_llu() {int ip=getchar_unlocked();llu ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked());for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return ret;}
  38.  
  39. //end of fast input
  40.  
  41. //fast output
  42.  
  43. //no line break
  44. void print_d(int n) {if(n<0){n=-n;putchar_unlocked('-');}int i=10;char output_buffer[10];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<10);}
  45. void print_ld(ld n) {if(n<0){n=-n;putchar_unlocked('-');}int i=11;char output_buffer[11];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<11);}
  46. void print_lld(lld n) {if(n<0){n=-n;putchar_unlocked('-');}int i=21;char output_buffer[21];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<21);}
  47. void print_llu(llu n) {int i=21;char output_buffer[21];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<21);}
  48.  
  49. //new line
  50. void println_d(int n) {if(n<0){n=-n;putchar_unlocked('-');}int i=10;char output_buffer[11];output_buffer[10]='\n';do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<11);}
  51. void println_ld(ld n) {if(n<0){n=-n;putchar_unlocked('-');}int i=11;char output_buffer[12];output_buffer[11]='\n';do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<12);}
  52. void println_lld(lld n) {if(n<0){n=-n;putchar_unlocked('-');}int i=21;char output_buffer[22];output_buffer[21]='\n';do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<22);}
  53. void println_llu(llu n) {int i=21;char output_buffer[22];output_buffer[21]='\n';do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<22);}
  54.  
  55. //special char
  56. char sp;
  57. void printsp_d(int n) {if(n<0){n=-n;putchar_unlocked('-');}int i=10;char output_buffer[11];output_buffer[10]=sp;do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<11);}
  58. void printsp_ld(ld n) {if(n<0){n=-n;putchar_unlocked('-');}int i=11;char output_buffer[12];output_buffer[11]=sp;do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<12);}
  59. void printsp_lld(lld n) {if(n<0){n=-n;putchar_unlocked('-');}int i=21;char output_buffer[22];output_buffer[21]=sp;do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<22);}
  60. void printsp_llu(llu n) {int i=21;char output_buffer[22];output_buffer[21]=sp;do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<22);}
  61.  
  62. //end of fast output
  63.  
  64.  
  65. //extra functions
  66.  
  67. //end of extra fnctions
  68.  
  69.  
  70. map<string,int>cnt;
  71. map<string,int>sps;
  72. vector<string>all;
  73.  
  74. //main
  75.  
  76. int main()
  77. {
  78. int t=scan_d();
  79. while(t--)
  80. {
  81. int n=scan_d(),m=scan_d();
  82. string arr[n];
  83. for(int i=0;i<n;i++)
  84. cin>>arr[i];
  85. for(int i=0;i<n;i++)
  86. {
  87. for(int j=0;j<m;j++)
  88. {
  89. for(int k=i;k<n;k++)
  90. {
  91. for(int l=j;l<m;l++)
  92. {
  93. string s="";
  94. int spaces=0;
  95. for(int o=i;o<=k;o++)
  96. {
  97. for(int p=j;p<=l;p++)
  98. {
  99. s+=arr[o][p];
  100. }
  101. spaces++;
  102. s+=" ";
  103. }
  104. //cout<<s<<endl;
  105. if(!cnt[s])
  106. {
  107. cnt[s]=1;
  108. all.push_back(s);
  109. sps[s]=spaces;
  110. }
  111. else
  112. cnt[s]++;
  113. }
  114. }
  115. }
  116. }
  117. int max=0;
  118. int len=all.size();
  119. for(int i=0;i<len;i++)
  120. {
  121. //cout<<all[i]<<endl;
  122. if((cnt[all[i]]>=2)&&(all[i].length()-sps[all[i]])>max)
  123. max=all[i].length()-sps[all[i]];
  124. }
  125. println_d(max);
  126. all.clear();
  127. cnt.clear();
  128. sps.clear();
  129. }
  130. return 0;
  131. }
  132.  
  133. //end of main
Success #stdin #stdout 0s 3444KB
stdin
4
3 5
ababa
ababa
ccccc
4 5
xyyyx
yxxyy
xyyxy
xxyyx
2 2
ab
cd
2 2
aa
bc
stdout
9
6
0
1