Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define LL long long
- #define N ((int)6e4 + 5)
- #define MOD ((int)998244353 + 0)
- #define MAX ((int)1e9 + 7)
- #define MAXL ((ll)1e18 + 7)
- #define MAXP ((int)1e3 + 7)
- #define thr 1e-8
- #define pi acos(-1) /// pi = acos ( -1 )
- #define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
- #define endl "\n"
- using namespace std;
- string str[102];
- int dxx[] = {-1,0,1,0}; /// dxx[3] , dyy[3] -> left
- int dyy[] = {0,1,0,-1};
- int dis[100][100];
- bool IsValid(int row , int col)
- {
- if(min(row , col) < 0 || row >= n || col >= m || str[row][col] == '#' || str[row][col] == 'm') return 0;
- }
- void bfs(int row , int col){
- memset(dis,-,sizeof dis);
- queue < pair < int , int > > que;
- que.push({row , col});
- // vis[row][col] = 1;
- dis[row][col] = 0;
- while(!que.empty()){
- int row = que.front().first , col = que.front().second;
- que.pop();
- for(int i = 0 ; i < 4 ; i++){
- int x = row + dxx[i] , y = col + dyy[i];
- if(IsValid(x,y) && dis[x][y] == -){
- dis[x][y] = dis[row][col] + 1;
- que.push({x,y});
- }
- }
- }
- }
- int main()
- {
- /// problem: https://lightoj.com/problem/power-puff-girls
- int t;
- cin>>t;
- while(t--){
- int n , m;
- cin>>n>>m;
- for(int i = 0 ; i < n ; i++){
- cin>>str[i];
- }
- for(int i = 0 ; i < n ; i++){
- for(int j = 0 ; j < m ; j++){
- if(str[i][j] == 'h') bfs(i , j);
- }
- }
- int ans = 0;
- for(int i = 0 ; i < n ; i++){
- for(int j = 0 ; j < m ; j++){
- if(str[i][j] >= 'a' && str[i][j] <= 'c') ans = max(ans , dis[i][j]);
- }
- }
- cout<<ans<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement