#P9931. [NFLSPC #6] 挑战停机问题
[NFLSPC #6] 挑战停机问题
Background
As an OIer/XCPCer in the new era, you are no longer satisfied with challenging NP-complete problems. You want to challenge the undecidability in mathematics—the Turing halting problem.
Problem Description
Turing gives you a program. At the very beginning of the program, there is one and only one variable , with initial value . The program has lines, numbered . Each line is one of the following forms:
A a: Set , then execute the next line.G x: Execute line .I l r x y: If , execute line ; otherwise, execute line .E: Terminate the program immediately.
It is guaranteed that the last line is E.
Turing wants you to determine whether this program will terminate when executed starting from line 1. To further test whether you can really decide the halting problem (or you are just pretending?), Turing also requires you to output the final value of . If the program does not terminate and there does not exist a moment after which no longer changes, output @Turing ?.
Input Format
This problem contains multiple test cases. The first line contains a positive integer indicating the number of test cases. For each test case:
- The first line contains an integer , indicating the number of lines in the program.
- The next lines describe the program.
Output Format
For each test case, output two lines:
- The first line outputs a string
YesorNo, indicating whether the program will terminate. - The second line outputs an integer or the string
@Turing ?, indicating the final value of .
3
5
I 1 7 1 3
G 4
A 2
G 2
E
6
A 2
I 2 3 5 1
E
G 4
A 1
E
4
A 1
G 1
E
E
No
2
Yes
3
No
@Turing ?
Hint
For all testdata, , , , , . It is guaranteed that all numbers in the input are integers.
- Subtask 1 (15 points): There are no
Istatements. - Subtask 2 (20 points): .
- Subtask 3 (40 points): .
- Subtask 4 (25 points): No special constraints.
Source: NFLSPC #6 G by chenxia25
Translated by ChatGPT 5