#P16396. [ECUSTPC 2026 Spring] 左灯右行
[ECUSTPC 2026 Spring] 左灯右行
Background
:::epigraph I love you in a way. :::
Problem Description
This problem shares the same background as Problem E “Right Light, Left Walk”. The two problems are closely related, so it is recommended to read the other problem’s statement before attempting either one.
This is an interactive problem.
Little T is puzzled by the metro map of City T...
Specifically, the city lies on both sides of the E River. On the north bank there are metro stations , and on the south bank there are metro stations .
City T has a total of metro lines. Each line is a loop line. For the -th loop line, the stations it connects are . However, these loop lines are all one-way. The direction may be $N_i \leftarrow N_{i+1} \leftarrow S_{i+1} \leftarrow S_i \leftarrow N_i$, or it may be .
Each loop line has a price list , representing the cost of riding one stop between the following 4 pairs of adjacent stations: (, , , and ). Note that the travel direction for riding one stop is determined by the operating direction of the loop line; it could be or .
Unfortunately, a spacetime black hole has swallowed both the operating directions and the prices on the price lists. Little T plans to ask Big K for help to find out the operating direction of each metro line.
Big K knows the operating directions. However, for each loop line, Little T may arbitrarily assign a new set of prices for its four adjacent edges. Big K knows the true operating directions, and will answer Little T’s queries based on these assigned prices.
Little T may ask at most questions:
- From station (it can be or , same below) to station , riding the metro under the fare table assigned by Little T, what is the minimum metro cost that must be paid?
- If different loop lines connect the same pair of adjacent stations, then all those edges exist simultaneously and can all be used. The cost of one trip is the sum of the weights of the edges traveled, and transfers at stations have no extra cost.
After asking these questions, Little T must confirm with Big K the operating direction of each metro line.
Please help Little T solve this problem.
Note that the directions of the metro lines are predetermined and will not change during the interaction. In other words, the interactor is not adaptive.
Interaction Protocol
For each test point, there is only one set of testdata.
The first line contains an integer , indicating the parameter. There are stations in total and loop lines in total.
You must first output lines. In the -th line, output 4 integers , representing the movement costs between the 4 pairs of adjacent stations on the -th loop line: , , , and . You must guarantee that these four integers are in .
Then the interaction starts immediately. In each interaction, you may ask the interactor a question in the following format:
- Output one line. First output a character
?to indicate a query, then output 4 elements . You must ensure that and $id_x, id_y \in \{m \in \mathbb{N} : 1 \le m \le n\}$. This means Little T asks Big K: from the -th station on bank , i.e. , to the -th station on bank , i.e. , what is the minimum metro cost that must be paid. - If your query is valid and you have not exceeded the query limit, the interactor will output one line containing an integer , representing the minimum metro cost between the two stations.
- If you exceed the corresponding query limit, the interactor will output an integer and terminate your interaction process. In this case, you will receive a Wrong Answer verdict.
If you have determined the metro directions, output the answer in the following format:
- Output one line. First output a character
!, then output a string of length . The -th character . If , it means the direction of the -th loop line is $N_i \leftarrow N_{i+1} \leftarrow S_{i+1} \leftarrow S_i \leftarrow N_i$. If , it means the direction of the -th loop line is .
After outputting the answer, you should exit safely.
Each output must end with a newline and flush the buffer, otherwise you may get unexpected results.
To flush the buffer, you can:
- For C or C++, use
fflush(stdout)orcout.flush(). - For Java or Kotlin, use
System.out.flush(). - For Python, use
stdout.flush().
3
10
12
10 3 1 2
10 10 1 1
? N 1 N 2
? N 2 N 3
! OI
Hint
Explanation for Sample 1
:::align{center}
:::
The figure above shows the operating directions of the metro and Little T’s price markings.
Note that the interactive process in the sample is for reference only. The actual interactive process is not unique, and this example’s interactive process may not be feasible or optimal. The sample for this problem will not appear in the additional files.
Translated by ChatGPT 5