fork download
  1. #include<bits/stdc++.h>
  2. #define loop(i,a,b) for(int i=a;i<b;i++)
  3. #define loopb(i,a,b) for(int i=a;i>=b;i--)
  4. #define loopm(i,a,b,step) for(int i=a;i<b;i+=step)
  5. #define loopbm(i,a,b,step) for(int i=a;i>=b;i-=step)
  6. #define pb(a) push_back(a)
  7. #define mp(a,b) make_pair(a,b)
  8. #define init(arr,val) memset(arr,val,sizeof(arr))
  9. #define INF 1000000007
  10. #define BINF 1000000000000000001
  11. #define int long long int
  12. #define double long double
  13.  
  14. using namespace std;
  15.  
  16. string grid[55];
  17.  
  18.  
  19.  
  20. int h,w;
  21.  
  22. bool isvalid(int i,int j)
  23. {
  24. if(i<0 or j<0 or i>=h or j>=w) return false;
  25. return true;
  26. }
  27.  
  28.  
  29. int height[55][55];
  30.  
  31. int dfs(int n,int m)
  32. {
  33.  
  34. if(height[n][m]>0) return height[n][m];
  35.  
  36. int ans=0;
  37.  
  38. loop(i,n-1,n+2)
  39. {
  40. loop(j,m-1,m+2)
  41. {
  42.  
  43. if(isvalid(i,j)){
  44.  
  45. if((char)grid[i][j]==(char)(grid[n][m]+1)){
  46. //cout<<"{"<<n<<" "<<m<<"}->"<<"{"<<i<<" "<<j<<"}\n";
  47. ans=max(ans,dfs(i,j));
  48. }
  49. }
  50. }
  51. }
  52.  
  53. ans+=1;
  54. height[n][m]=ans;
  55. return ans;
  56.  
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. #undef int
  67. int main()
  68. {
  69. #define int long long int
  70. ios_base::sync_with_stdio(false);
  71. cin.tie(NULL);
  72. cout.tie(NULL);
  73. freopen("input.txt","r",stdin);
  74. int tc=1;
  75. while(1)
  76. {
  77.  
  78.  
  79. cin>>h>>w;
  80. if(h==0) break;
  81. cout<<"Case "<<tc<<": ";
  82. tc++;
  83. loop(i,0,h) cin>>grid[i];
  84.  
  85.  
  86.  
  87. loop(i,0,55)
  88. {
  89. loop(j,0,55) height[i][j]=0;
  90. }
  91.  
  92. loop(i,0,h)
  93. {
  94. loop(j,0,w)
  95. {
  96. if(grid[i][j]=='A') dfs(i,j);
  97. }
  98. }
  99.  
  100. int ans=0;
  101.  
  102. loop(i,0,h)
  103. {
  104. loop(j,0,w) ans=max(ans,height[i][j]);
  105. }
  106.  
  107.  
  108. cout<<ans<<endl;
  109. }
  110.  
  111. return 0;
  112. }#include <iostream>
  113. using namespace std;
  114.  
  115. int main() {
  116. // your code goes here
  117. return 0;
  118. }#include<bits/stdc++.h>
  119. #define loop(i,a,b) for(int i=a;i<b;i++)
  120. #define loopb(i,a,b) for(int i=a;i>=b;i--)
  121. #define loopm(i,a,b,step) for(int i=a;i<b;i+=step)
  122. #define loopbm(i,a,b,step) for(int i=a;i>=b;i-=step)
  123. #define pb(a) push_back(a)
  124. #define mp(a,b) make_pair(a,b)
  125. #define init(arr,val) memset(arr,val,sizeof(arr))
  126. #define INF 1000000007
  127. #define BINF 1000000000000000001
  128. #define int long long int
  129. #define double long double
  130.  
  131. using namespace std;
  132.  
  133. string grid[55];
  134.  
  135.  
  136.  
  137. int h,w;
  138.  
  139. bool isvalid(int i,int j)
  140. {
  141. if(i<0 or j<0 or i>=h or j>=w) return false;
  142. return true;
  143. }
  144.  
  145.  
  146. int height[55][55];
  147.  
  148. int dfs(int n,int m)
  149. {
  150.  
  151. if(height[n][m]>0) return height[n][m];
  152.  
  153. int ans=0;
  154.  
  155. loop(i,n-1,n+2)
  156. {
  157. loop(j,m-1,m+2)
  158. {
  159.  
  160. if(isvalid(i,j)){
  161.  
  162. if((char)grid[i][j]==(char)(grid[n][m]+1)){
  163. //cout<<"{"<<n<<" "<<m<<"}->"<<"{"<<i<<" "<<j<<"}\n";
  164. ans=max(ans,dfs(i,j));
  165. }
  166. }
  167. }
  168. }
  169.  
  170. ans+=1;
  171. height[n][m]=ans;
  172. return ans;
  173.  
  174. }
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183. #undef int
  184. int main()
  185. {
  186. #define int long long int
  187. ios_base::sync_with_stdio(false);
  188. cin.tie(NULL);
  189. cout.tie(NULL);
  190. freopen("input.txt","r",stdin);
  191. int tc=1;
  192. while(1)
  193. {
  194.  
  195.  
  196. cin>>h>>w;
  197. if(h==0) break;
  198. cout<<"Case "<<tc<<": ";
  199. tc++;
  200. loop(i,0,h) cin>>grid[i];
  201.  
  202.  
  203.  
  204. loop(i,0,55)
  205. {
  206. loop(j,0,55) height[i][j]=0;
  207. }
  208.  
  209. loop(i,0,h)
  210. {
  211. loop(j,0,w)
  212. {
  213. if(grid[i][j]=='A') dfs(i,j);
  214. }
  215. }
  216.  
  217. int ans=0;
  218.  
  219. loop(i,0,h)
  220. {
  221. loop(j,0,w) ans=max(ans,height[i][j]);
  222. }
  223.  
  224.  
  225. cout<<ans<<endl;
  226. }
  227.  
  228. return 0;
  229. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:112:2: error: stray ‘#’ in program
 }#include <iostream>
  ^
prog.cpp:118:2: error: stray ‘#’ in program
 }#include<bits/stdc++.h>
  ^
prog.cpp:112:3: error: ‘include’ does not name a type
 }#include <iostream>
   ^~~~~~~
prog.cpp:115:10: error: ‘::main’ must return ‘int’
 int main() {
          ^
prog.cpp: In function ‘int main()’:
prog.cpp:115:5: error: redefinition of ‘int main()’
 int main() {
     ^~~~
prog.cpp:67:5: note: ‘int main()’ previously defined here
 int main()
     ^~~~
prog.cpp: At global scope:
prog.cpp:118:3: error: ‘include’ does not name a type
 }#include<bits/stdc++.h>
   ^~~~~~~
prog.cpp:133:15: error: redefinition of ‘std::__cxx11::string grid [55]’
 string grid[55];
               ^
prog.cpp:16:8: note: ‘std::__cxx11::string grid [55]’ previously declared here
 string grid[55];
        ^~~~
prog.cpp:137:5: error: redefinition of ‘long long int h’
 int h,w;
     ^
prog.cpp:20:5: note: ‘long long int h’ previously declared here
 int h,w;
     ^
prog.cpp:137:7: error: redefinition of ‘long long int w’
 int h,w;
       ^
prog.cpp:20:7: note: ‘long long int w’ previously declared here
 int h,w;
       ^
prog.cpp: In function ‘bool isvalid(long long int, long long int)’:
prog.cpp:139:7: error: redefinition of ‘bool isvalid(long long int, long long int)’
 bool  isvalid(int i,int j)
       ^~~~~~~
prog.cpp:22:7: note: ‘bool isvalid(long long int, long long int)’ previously defined here
 bool  isvalid(int i,int j)
       ^~~~~~~
prog.cpp: At global scope:
prog.cpp:146:18: error: redefinition of ‘long long int height [55][55]’
 int height[55][55];
                  ^
prog.cpp:29:5: note: ‘long long int height [55][55]’ previously declared here
 int height[55][55];
     ^~~~~~
prog.cpp: In function ‘long long int dfs(long long int, long long int)’:
prog.cpp:148:5: error: redefinition of ‘long long int dfs(long long int, long long int)’
 int dfs(int n,int m)
     ^~~
prog.cpp:31:5: note: ‘long long int dfs(long long int, long long int)’ previously defined here
 int dfs(int n,int m)
     ^~~
prog.cpp: In function ‘int main()’:
prog.cpp:184:5: error: redefinition of ‘int main()’
 int main()
     ^~~~
prog.cpp:67:5: note: ‘int main()’ previously defined here
 int main()
     ^~~~
stdout
Standard output is empty