fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int visited[NMAX][NMAX];
  4. int cx[]={0,0,-1,1};
  5. int cy[]={1,-1,0,0};
  6. int outside(int i,int j,int n,int m)
  7. {
  8. if(i>=0&&j>=0&&i<n&&j<n)
  9. return 1;
  10. else return 0;
  11. }
  12.  
  13. int dfs(char cake[NMAX][NMAX],int i,int j,int n)
  14. {
  15. if(visited[i][j]==1)
  16. return 0;
  17. // cout<<"i : "<<i<<" "<<"j : "<<j<<endl;
  18. visited[i][j]=1;
  19. int count=1;
  20. for(int k=0;k<4;k++)
  21. {
  22. int x=i+cx[k];
  23. int y=i+cy[k];
  24. if(outside(x,y,n,n) && cake[x][y]=='1')
  25. {
  26. count+=dfs(cake,x,y,n);
  27. }
  28. }
  29. return count;
  30. }
  31. int solve(int n,char cake[NMAX][NMAX])
  32. {
  33. memset(visited,0,sizeof(visited));
  34. int maximise=0;
  35. for(int i=0;i<n;i++)
  36. {
  37. for(int j=0;j<n;j++)
  38. {
  39. if(cake[i][j]=='1' && visited[i][j]==0)
  40. {
  41. maximise=max(maximise,dfs(cake,i,j,n));
  42. }
  43. }
  44. }
  45. return maximise;
  46. }
  47.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:13: error: ‘NMAX’ was not declared in this scope
 int visited[NMAX][NMAX];
             ^~~~
prog.cpp:3:13: note: suggested alternative: ‘NAN’
 int visited[NMAX][NMAX];
             ^~~~
             NAN
prog.cpp:3:19: error: ‘NMAX’ was not declared in this scope
 int visited[NMAX][NMAX];
                   ^~~~
prog.cpp:3:19: note: suggested alternative: ‘NAN’
 int visited[NMAX][NMAX];
                   ^~~~
                   NAN
prog.cpp:13:19: error: ‘NMAX’ was not declared in this scope
 int dfs(char cake[NMAX][NMAX],int i,int j,int n)
                   ^~~~
prog.cpp:13:19: note: suggested alternative: ‘NAN’
 int dfs(char cake[NMAX][NMAX],int i,int j,int n)
                   ^~~~
                   NAN
prog.cpp:13:25: error: ‘NMAX’ was not declared in this scope
 int dfs(char cake[NMAX][NMAX],int i,int j,int n)
                         ^~~~
prog.cpp:13:25: note: suggested alternative: ‘NAN’
 int dfs(char cake[NMAX][NMAX],int i,int j,int n)
                         ^~~~
                         NAN
prog.cpp:13:30: error: expected ‘)’ before ‘,’ token
 int dfs(char cake[NMAX][NMAX],int i,int j,int n)
        ~                     ^
                              )
prog.cpp:13:31: error: expected unqualified-id before ‘int’
 int dfs(char cake[NMAX][NMAX],int i,int j,int n)
                               ^~~
prog.cpp:31:27: error: ‘NMAX’ was not declared in this scope
 int solve(int n,char cake[NMAX][NMAX])
                           ^~~~
prog.cpp:31:27: note: suggested alternative: ‘NAN’
 int solve(int n,char cake[NMAX][NMAX])
                           ^~~~
                           NAN
prog.cpp:31:33: error: ‘NMAX’ was not declared in this scope
 int solve(int n,char cake[NMAX][NMAX])
                                 ^~~~
prog.cpp:31:33: note: suggested alternative: ‘NAN’
 int solve(int n,char cake[NMAX][NMAX])
                                 ^~~~
                                 NAN
prog.cpp: In function ‘int solve(...)’:
prog.cpp:33:9: error: ‘visited’ was not declared in this scope
  memset(visited,0,sizeof(visited));
         ^~~~~~~
prog.cpp:33:9: note: suggested alternative: ‘finitel’
  memset(visited,0,sizeof(visited));
         ^~~~~~~
         finitel
prog.cpp:35:19: error: ‘n’ was not declared in this scope
     for(int i=0;i<n;i++)
                   ^
prog.cpp:39:16: error: ‘cake’ was not declared in this scope
             if(cake[i][j]=='1' && visited[i][j]==0)
                ^~~~
stdout
Standard output is empty