Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID:goharsh1
- TASK:castle
- LANG:C++
- */
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- using namespace std;
- ifstream fin("castle.in");
- ofstream fout("castle.out");
- #define cin fin
- #define cout fout
- int castle[100][100];
- int roomof[100][100];
- int sizer[100*100];
- int m,n;
- int dfs(int i,int j,int room)
- {
- if(roomof[i][j]!=0)
- return 0;
- roomof[i][j]=room;
- int size=1;
- int temp=castle[i][j];
- bool n,s,e,w;
- n=s=e=w=true;
- if(temp>=8)
- {
- s=false;
- temp-=8;
- }
- if(temp>=4)
- {
- e=false;
- temp-=4;
- }
- if(temp>=2)
- {
- n=false;
- temp-=2;
- }
- if(temp>=1)
- {
- temp--;
- w=false;
- }
- if(s)
- size+=dfs(i+1,j,room);
- if(n)
- size+=dfs(i-1,j,room);
- if(e)
- size+=dfs(i,j+1,room);
- if(w)
- size+=dfs(i,j-1,room);
- sizer[room]=size;
- return size;
- }
- int main()
- {
- cin>>m>>n;
- for(int i=0;i<n;i++)
- for(int j=0;j<m;j++)
- cin>>castle[i][j];
- int room=0;//number of rooms
- int maxroom=0;//size of largest room
- for(int i=0;i<n;i++)
- for(int j=0;j<m;j++)
- {
- if(roomof[i][j]==0)
- {
- maxroom=max(dfs(i,j,++room),maxroom);
- }
- }
- cout<<room<<endl;
- cout<<maxroom<<endl;
- //after wall
- char c='A';
- int maxsize=0;
- int maxi=-1,maxj=-1;
- for(int j=0;j<m;j++)
- for(int i=n-1;i>=0;i--)
- {
- //north
- if(i-1>=0&&roomof[i][j]!=roomof[i-1][j])
- {
- if(sizer[roomof[i][j]]+sizer[roomof[i-1][j]]>maxsize)
- {
- maxsize=sizer[roomof[i][j]]+sizer[roomof[i-1][j]];
- maxi=i;
- maxj=j;
- c='N';
- }
- }
- //east
- if(j+1<m&&roomof[i][j]!=roomof[i][j+1])
- {
- if(sizer[roomof[i][j]]+sizer[roomof[i][j+1]]>maxsize)
- {
- maxsize=sizer[roomof[i][j]]+sizer[roomof[i][j+1]];
- maxi=i;
- maxj=j;
- c='E';
- }
- }
- }
- cout<<maxsize<<endl;
- cout<<maxi+1<<" "<<maxj+1<<" "<<c<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment