Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task :
- Author : Phumipat C. [MAGCARI]
- Language : C++
- */
- #include<bits/stdc++.h>
- using namespace std;
- struct A{
- int i,j,t;
- };
- vector<pair<int ,int > > g[110][110];
- int ti[110][110];
- queue<A > que;
- int main(){
- int r,c;
- char temp;
- scanf("%d %d",&r,&c);
- for(int i=1;i<=r;i++){
- for(int j=1;j<=c;j++){
- scanf(" %c",&temp);
- if(temp == 'B'){
- g[i][j].push_back({i+1,j});
- g[i][j].push_back({i,j+1});
- g[i+1][j].push_back({i,j});
- g[i][j+1].push_back({i,j});
- }else if(temp == 'R'){
- g[i][j].push_back({i,j+1});
- g[i][j+1].push_back({i,j});
- }else if(temp == 'D'){
- g[i][j].push_back({i+1,j});
- g[i+1][j].push_back({i,j});
- }
- }
- }
- que.push({1,1,1});
- ti[1][1] = 1;
- while(!que.empty()){
- auto now = que.front();
- que.pop();
- for(auto x:g[now.i][now.j]){
- if(ti[x.first][x.second]){
- if(ti[x.first][x.second] == now.t+1){
- printf("%d\n%d %d\n",now.t+1,x.first,x.second);
- return 0;
- }else{
- continue;
- }
- }
- ti[x.first][x.second] = now.t+1;
- que.push({x.first,x.second,now.t+1});
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement