forked from DionysiosB/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1607E-RobotOnTheBoard.cpp
More file actions
34 lines (25 loc) · 855 Bytes
/
1607E-RobotOnTheBoard.cpp
File metadata and controls
34 lines (25 loc) · 855 Bytes
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
#include <iostream>
int main(){
std::ios_base::sync_with_stdio(false);
long t; std::cin >> t;
while(t--){
long n, m; std::cin >> n >> m;
std::string s; std::cin >> s;
long x(0), y(0), minx(0), maxx(0), miny(0), maxy(0);
for(char c : s){
if (c == 'L'){--y; miny = (miny < y ? miny : y);}
else if(c == 'R'){++y; maxy = (maxy > y ? maxy : y);}
else if(c == 'U'){--x; minx = (minx < x ? minx : x);}
else if(c == 'D'){++x; maxx = (maxx > x ? maxx : x);}
if(maxx >= n + minx){
minx += (x == minx);
break;
}
if(maxy >= m + miny){
miny += (y == miny);
break;
}
}
std::cout << (1 - minx) << " " << (1 - miny) << std::endl;
}
}