fork download
  1. int vis[1000][1000],comp[1000][1000];
  2. int dx[]={-1,1,0,0};
  3. int dy[]={0,0,1,-1};
  4. int pqr[1000005];
  5. int n,m;
  6. vector<vector<char>>arr;
  7. bool check(int x, int y)
  8. {
  9. if(x>=0&&x<n&&y>=0&&y<m&&arr[x][y]=='O'&&!vis[x][y])
  10. return true;
  11. return false;
  12. }
  13. void dfs(int x, int y,int id)
  14. {
  15.  
  16. {
  17. vis[x][y]=1;
  18. comp[x][y] = id;
  19. for(int i=0;i<4;i++)
  20. {
  21. int xx = x +dx[i];
  22. int yy = y +dy[i];
  23. if(check(xx,yy))
  24. dfs(xx,yy,id);
  25. }
  26. }
  27. }
  28. void flip(int x,int y)
  29. {
  30. if(comp[x][y]&&!pqr[comp[x][y]])
  31. arr[x][y]='X';
  32. }
  33. void solve()
  34. {
  35. memset(vis, 0, sizeof(vis));
  36. memset(comp,0,sizeof(comp));
  37. memset(pqr,0,sizeof(pqr));
  38. n = A.size();
  39. m = A[0].size();
  40. int id=1;
  41. for(int i=0;i<n;i++)
  42. for (int j=0;j<m;j++)
  43. {
  44. if(check(i,j))
  45. {dfs(i,j,id);
  46. id++;}
  47. }
  48. for(int i=0;i<n;i++)
  49. {
  50. if(i==0||i==n-1)
  51. {
  52. for(int j=0;j<m;j++)
  53. pqr[comp[i][j]]=1;
  54. }
  55. else
  56. {
  57. pqr[comp[i][0]]=1;
  58. pqr[comp[i][m-1]]=1;
  59. }
  60. }
  61. for(int i=0;i<n;i++)
  62. for (int j=0;j<m;j++)
  63. {
  64. flip(i,j);
  65. }
  66. }
  67.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:6:1: error: 'vector' does not name a type
 vector<vector<char>>arr;
 ^
prog.cpp: In function 'bool check(int, int)':
prog.cpp:9:30: error: 'arr' was not declared in this scope
     if(x>=0&&x<n&&y>=0&&y<m&&arr[x][y]=='O'&&!vis[x][y])
                              ^
prog.cpp: In function 'void flip(int, int)':
prog.cpp:31:9: error: 'arr' was not declared in this scope
         arr[x][y]='X';
         ^
prog.cpp: In function 'void solve()':
prog.cpp:35:31: error: 'memset' was not declared in this scope
     memset(vis, 0, sizeof(vis));
                               ^
prog.cpp:38:9: error: 'A' was not declared in this scope
     n = A.size();
         ^
stdout
Standard output is empty