Advertisement
MAGCARI

Sewer

Sep 21st, 2022
1,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. /*
  2.     Task        :
  3.     Author      : Phumipat C. [MAGCARI]
  4.     Language    : C++
  5. */
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8. struct A{
  9.     int i,j,t;
  10. };
  11. vector<pair<int ,int > > g[110][110];
  12. int ti[110][110];
  13. queue<A > que;
  14. int main(){
  15.     int r,c;
  16.     char temp;
  17.     scanf("%d %d",&r,&c);
  18.     for(int i=1;i<=r;i++){
  19.         for(int j=1;j<=c;j++){
  20.             scanf(" %c",&temp);
  21.             if(temp == 'B'){
  22.                 g[i][j].push_back({i+1,j});
  23.                 g[i][j].push_back({i,j+1});
  24.                 g[i+1][j].push_back({i,j});
  25.                 g[i][j+1].push_back({i,j});
  26.             }else if(temp == 'R'){
  27.                 g[i][j].push_back({i,j+1});
  28.                 g[i][j+1].push_back({i,j});
  29.             }else if(temp == 'D'){
  30.                 g[i][j].push_back({i+1,j});
  31.                 g[i+1][j].push_back({i,j});
  32.             }
  33.         }
  34.     }
  35.     que.push({1,1,1});
  36.     ti[1][1] = 1;
  37.     while(!que.empty()){
  38.         auto now = que.front();
  39.         que.pop();
  40.         for(auto x:g[now.i][now.j]){
  41.             if(ti[x.first][x.second]){
  42.                 if(ti[x.first][x.second] == now.t+1){
  43.                     printf("%d\n%d %d\n",now.t+1,x.first,x.second);
  44.                     return 0;
  45.                 }else{
  46.                     continue;
  47.                 }
  48.             }
  49.             ti[x.first][x.second] = now.t+1;
  50.             que.push({x.first,x.second,now.t+1});
  51.         }
  52.     }
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement