fork download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <cmath>
  13. #include <iomanip>
  14. #define dibs reserve
  15. #define OVER9000 1234567890
  16. #define patkan 9
  17. #define tisic 47
  18. #define soclose 1e-9
  19. #define pi 3.1415926535898
  20. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  21. #define chocolate win
  22. #define ff first
  23. #define ss second
  24. #define abs(x) ((x < 0)?-(x):(x))
  25. #define uint unsigned int
  26. // mylittlepony
  27. using namespace std;
  28.  
  29. int main() {
  30. // freopen("skicourse.in","r",stdin);
  31. // freopen("skicourse.out","w",stdout);
  32. int N,M;
  33. scanf(" %d %d",&N,&M);
  34. vector< vector<bool> > isS, isR, isC;
  35. isS.resize(N, vector<bool>(M,false));
  36. isR.resize(N, vector<bool>(M,false));
  37. isC.resize(N, vector<bool>(M,false));
  38. char c[142];
  39. for(int i =0; i < N; i++) {
  40. scanf(" %s",c);
  41. for(int j =0; j < M; j++) {
  42. if(c[j] == 'R') isR[i][j] =true;
  43. else isS[i][j] =true;}}
  44.  
  45. vector< vector<int> > sumS, sumR, sumC;
  46. sumS.resize(N+1, vector<int>(M+1,0));
  47. sumR.resize(N+1, vector<int>(M+1,0));
  48. sumC.resize(N+1, vector<int>(M+1,0));
  49. for(int i =0; i < N; i++) for(int j =0; j < M; j++) {
  50. sumS[i+1][j+1] =(int)(isS[i][j])+sumS[i+1][j]+sumS[i][j+1]-sumS[i][j];
  51. sumR[i+1][j+1] =(int)(isR[i][j])+sumR[i+1][j]+sumR[i][j+1]-sumR[i][j];}
  52.  
  53. int B =min(N,M);
  54. set< pair<int,int> > F;
  55. for(int i =0; i < N; i++) for(int j =0; j < M; j++) F.insert(make_pair(i,j));
  56.  
  57. while(sumC[N][M] < N*M) {
  58. bool b =false;
  59. vector< pair<int,int> > D;
  60. for(set< pair<int,int> >::iterator it =F.begin(); it != F.end(); it++) {
  61. if(it->ff+B > N || it->ss+B > M) continue;
  62. // da sa vyfarbit, je v nom daco nove?
  63. int s =sumC[it->ff+B][it->ss+B]+sumC[it->ff][it->ss]-sumC[it->ff+B][it->ss]-sumC[it->ff][it->ss+B];
  64. if(s == B*B) {
  65. D.push_back(*it);
  66. continue;}
  67. int sS =sumS[it->ff+B][it->ss+B]+sumS[it->ff][it->ss]-sumS[it->ff+B][it->ss]-sumS[it->ff][it->ss+B];
  68. int sR =sumR[it->ff+B][it->ss+B]+sumR[it->ff][it->ss]-sumR[it->ff+B][it->ss]-sumR[it->ff][it->ss+B];
  69. if(max(sR,sS) < B*B) continue;
  70.  
  71. D.push_back(*it);
  72. for(int i =0; i < B; i++) for(int j =0; j < B; j++) if(isS[it->ff+i][it->ss+j]^isR[it->ff+i][it->ss+j]) {
  73. if(!isS[it->ff+i][it->ss+j])
  74. for(int k =it->ff+i+1; k <= N; k++)
  75. for(int l =it->ss+j+1; l <= M; l++)
  76. sumS[k][l]++;
  77. else for(int k =it->ff+i+1; k <= N; k++)
  78. for(int l =it->ss+j+1; l <= M; l++)
  79. sumR[k][l]++;
  80. for(int k =it->ff+i+1; k <= N; k++)
  81. for(int l =it->ss+j+1; l <= M; l++)
  82. sumC[k][l]++;
  83. isS[it->ff+i][it->ss+j] =isR[it->ff+i][it->ss+j] =true;}
  84. b =true;}
  85.  
  86. if(!b) B--;
  87. for(int i =0; i < D.size(); i++) F.erase(D[i]);}
  88.  
  89. printf("%d\n",B);
  90. return 0;}
  91.  
  92. // look at my code
  93. // my code is amazing
  94.  
Runtime error #stdin #stdout #stderr 0.36s 380224KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc