loj#P3236. 「POI2019 R1」Układ scalony
「POI2019 R1」Układ scalony
Description
Source Problem: POI XXVII - I etap (Układ scalony)
A new integrated circuit being developed by the Bytel company has memory chips arranged in rows and columns. The chip in the -th row and -th column (for has coordinates .
The chip in upper left corner, with coordinates , is supplied with power. To feed the remaining chips with power, further connections have to be made. Specifically, each chip should be connected to at least one of the adjacent chips on its left, right, top or bottom so that there exists a route connecting it with the chip in the upper left corner. The company’s electrical engineers insist that the longest path (between some pair of chips) in the connection network must have length exactly lest quantum effects render the circuit useless.
Write a program that will find such a connection network if it exists.
Input Format
In the first and only input line, there are three integers , , and which specify the circuit’s parameters: number of rows and columns, as well as desired length of the longest path.
Output Format
If there is no network with the desired properties, then the single word NIE
(Polish for no) should be printed to the output.
Otherwise, lines should be printed, the first one consisting of the word TAK
(Polish for yes), and each of the following lines containing four integers , separated by single spaces, which indicate that the network contains the connection between chips with coordinates and .
Should more than one correct solution exist, your program may report any of those.
2 3 4
TAK
1 1 1 2
1 1 2 1
1 2 2 2
2 3 2 2
1 2 1 3
2 3 1
NIE
Additional Samples
-
Additional Sample 1: ;
-
Additional Sample 2: ;
-
Additional Sample 3: .
Constraints
The set of tests consists of the following subsets. Within each subset, there may be several tests.
Your program will be awarded of the score for each test where it correctly prints TAK
to the first output line but then prints an incorrect network scheme.
For all test data, it is guaranteed that .
Subtask # | Additional Constraints | Score |
---|---|---|
, odd number of chips | ||
, even number of chips |