#P14445. [ICPC 2025 Xi'an Practice] Follow the Sequence
[ICPC 2025 Xi'an Practice] Follow the Sequence
题目描述
In a two-dimensional Cartesian coordinate system, you begin at the origin .
You are given a string of length , representing a walking sequence. The -th character belongs to the set .
An infinitely long string is constructed by repeating indefinitely. Formally, .
Now, you process each character of in order, moving according to the following rules:
- If , move to .
- If , move to .
- If , move to .
- If , move to .
This process continues indefinitely. You are also given key points, where the -th key point has coordinates . Your task is to determine the number of key points that are visited during the infinite walking process.
输入格式
The input consists of multiple test cases. The first line contains an integer (), the number of test cases. For each test case:
- The first line contains two integers and (), where is the length of the string and is the number of key points.
- The second line contains the string of length .
- The next lines each contain two integers and (), representing the coordinates of a key point.
It is guaranteed that the sum of and the sum of over all test cases do not exceed .
输出格式
For each test case, output a single line containing a single integer, representing the number of distinct key points visited.
3
6 3
DUDUDU
0 0
1 0
0 -1
6 5
DUDULU
0 0
-1 0
0 -1
-1 -1
-1 1
5 5
ULUUL
-624531741 651883826
-1 2
-312566309 468849463
-212530129 633866239
672824982 -674189680
2
4
2
提示
In the first test case, only two key points and are visited.
In the second test case, four key points and are visited.