-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathROBOTG.cpp
executable file
·49 lines (49 loc) · 1.03 KB
/
ROBOTG.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
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m,rm,rn;
cin>>n>>m;
char s[20];
cin>>s;
int lmax=0,rmax=0,umax=0,dmax=0,l=0,u=0,r=0,d=0;
for(int i=0;s[i]!='\0';i++)
{
if(s[i]=='L')
{
l++;
r--;
lmax=max(l,lmax);
}
else if(s[i]=='R')
{
l--;
r++;
rmax=max(r,rmax);
}
else if(s[i]=='D')
{
u--;
d++;
dmax=max(d,dmax);
}
else if(s[i]=='U')
{
d--;
u++;
umax=max(u,umax);
}
}
rn=rmax+lmax+1;
rm=umax+dmax+1;
if(rm<=n&&rn<=m)
cout<<"safe"<<endl;
else
cout<<"unsafe"<<endl;
}
}