Anti-Theft Road Planning Solution | Codeforces Problem Solution 2022
This is an interactive problem.
A city has buildings divided into a grid of rows and columns. You need to build a road of some length of your choice between each pair of adjacent by side buildings and . Due to budget limitations and legal restrictions, the length of each road must be a positive integer and the total length of all roads should not exceed .
There is a thief in the city who will start from the topmost, leftmost building (in the first row and the first column) and roam around the city, occasionally stealing artifacts from some of the buildings. He can move from one building to another adjacent building by travelling through the road which connects them.
You are unable to track down what buildings he visits and what path he follows to reach them. But there is one tracking mechanism in the city. The tracker is capable of storing a single integer which is initially . Each time the thief travels from a building to another adjacent building through a road of length , the tracker changes to . Each time the thief steals from a building, the tracker reports the value stored in it and resets it back to .
It is known beforehand that the thief will steal in exactly buildings but you will know the values returned by the tracker only after the thefts actually happen. Your task is to choose the lengths of roads in such a way that no matter what strategy or routes the thief follows, you will be able to exactly tell the location of all the buildings where the thefts occurred from the values returned by the tracker.
First read a single line containing two integers and denoting the number of rows and number of thefts respectively.
Let's denote the -th building in the -th row by .
Then print lines each containing integers. The -th integer of the -th line must be the value of .
Then print lines each containing integers. The -th integer of the -th line must be the value of .
Remember that the total length of the roads must not exceed .
Then answer queries. First read the value returned by the tracker. Then print two integers denoting the row number and column number of the building where the theft occurred. After that you will be able to answer the next query (if such exists).
After printing the answers do not forget to output end of line and flush the output buffer. Otherwise you will get the verdict Idleness limit exceeded. To flush the buffer, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- Read documentation for other languages.
Hacks
You cannot make hacks in this problem.
Join Now for Solution:-
No comments:
Post a Comment