Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int INF=1e9;
- using pii=pair<int,int>;
- int n,m;
- vector <int> g[10001];
- vector <int> dis(100001,INF);
- bool pst(int i,int j) {
- return i>=1 and i<=n and j>=1 and j<=m;
- }
- int drt(int i,int j){
- return m*(i-1)+j;
- }
- int I(int v){
- if(v%m!=0) return v/m+1;
- else return v/m;
- }
- int J(int v){
- v=v%m;
- if(v==0) return m;
- return v;
- }
- int main(){
- scanf("%d%d",&n,&m);
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- char a;
- int u,v;
- scanf(" %c",&a);
- u=drt(i,j);
- if(( a=='R' or a=='B' ) and pst(i,j+1)) {
- v=drt(i,j+1);
- g[u].push_back(v);
- g[v].push_back(u);
- }
- if(( a=='D' or a=='B') and pst(i+1,j)) {
- v=drt(i+1,j);
- g[u].push_back(v);
- g[v].push_back(u);
- }
- }
- }
- priority_queue <pii,vector<pii>,greater<pii>> pq;
- dis[1]=1;
- pq.push({1,1});
- while(pq.size()>0){
- int u,d;
- d=pq.top().first;
- u=pq.top().second;
- pq.pop();
- for(auto v:g[u]){
- if(d+1<dis[v]){
- dis[v]=d+1;
- pq.push({d+1,v});
- }
- else if(dis[v]==d+1){
- printf("%d\n%d %d",d+1,I(v),J(v));
- return 0;
- }
- }
- }
- return 0;
- }
- /*
- 3 3
- B R D
- D B N
- R N N
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement