-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
50 lines (48 loc) · 1.09 KB
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int vis[600][600];
int main()
{
int h,w,i,j,curi=0,curj=0,flag=0,step=0;
char ara[600][600];
cin>>h>>w;
for(i=0;i<h;i++)
{
for(j=0;j<w;j++)
cin>>ara[i][j];
}
vis[0][0]=1;
while(true)
{
if(curi==0 && ara[curi][curj]=='U')
break;
if(curi==h-1 && ara[curi][curj]=='D')
break;
if(curj==0 && ara[curi][curj]=='L')
break;
if(curj==w-1 && ara[curi][curj]=='R')
break;
if(ara[curi][curj]=='U')
curi--;
else if(ara[curi][curj]=='D')
curi++;
else if(ara[curi][curj]=='L')
curj--;
else if(ara[curi][curj]=='R')
curj++;
step++;
if(vis[curi][curj]==1)
{
flag=1;
break;
}
vis[curi][curj]=1;
//cout<<curi<<" "<<curj<<"\n";
}
if(flag==1)
cout<<-1<<"\n";
else
cout<<curi+1<<" "<<curj+1<<"\n";
return 0;
}