fork download
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. typedef long double ld;
  4. void fileio(){
  5. #ifdef LOCAL
  6. freopen("input.txt", "r", stdin);
  7. freopen("output.txt", "w", stdout);
  8. #endif
  9. }
  10. #define int ll
  11. #define ld long double
  12. #define all(v) v.begin(),v.end()
  13. #define rall(v) v.rbegin(),v.rend()
  14. #define START_TIMER auto start = std::chrono::high_resolution_clock::now();
  15. #define END_TIMER(msg) \
  16.   auto end = std::chrono::high_resolution_clock::now(); \
  17.   std::cout << msg << ": " \
  18.   << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() \
  19.   << " ms" << std::endl;
  20.  
  21. using namespace std;
  22. const double pi = 3.14159265358979;
  23.  
  24. int cnt=0;
  25. int H,W;
  26. vector<string> grid;
  27.  
  28. bool sym(int h1,int h2,int w1,int w2){
  29. int hh=h1+h2,ww=w1+w2;
  30. for (int i = h1; i <=h2; i++)
  31. {
  32. for (int j = w1; j <=w2; j++)
  33. {
  34. //cout<<hh-i<<" "<<ww-j<<endl;
  35. if(grid[i][j]!=grid[hh-i][ww-j]) return false;
  36. }
  37. }
  38. return true;
  39. }
  40.  
  41. void comp(int h,int w){
  42. for (int i = h; i < H; i++)
  43. {
  44. for (int j = w; j < W; j++)
  45. {
  46. if(sym(h,i,w,j)) cnt++;
  47. }
  48. }
  49.  
  50. }
  51.  
  52. void solve()
  53. {
  54. cin>>H>>W;
  55. grid.resize(H);
  56. for (int i = 0; i < H; i++)
  57. {
  58. cin>>grid[i];
  59. }
  60.  
  61. for (int i = 0; i < H; i++)
  62. {
  63. for (int j = 0; j < W; j++)
  64. {
  65. comp(i,j);
  66. }
  67. }
  68. cout<<cnt;
  69.  
  70. }
  71.  
  72. signed main()
  73. {
  74. fileio();
  75. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  76. ll t=1;//cin>>t;
  77. while(t--)
  78. {solve();}
  79. }
  80.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty