#P7170. [COCI 2020/2021 #3] Sateliti
[COCI 2020/2021 #3] Sateliti
Description
The captured image can be represented as an matrix, where * means a volcano and . means flat ground. We consider two images to belong to the same moon if and only if one can be obtained from the other by cyclically shifting (wrapping around) up/down or left/right.
The researchers want to find the lexicographically smallest image that belongs to the same moon as the given image. We concatenate all rows of an image in order into a single string, and compare images by the lexicographical order of these strings.
Input Format
The first line contains two integers , representing the size of the image.
The next lines each contain characters, describing the matrix of the image.
Output Format
Output lines, each containing characters, representing the lexicographically smallest image that satisfies the requirement.
3 3
.**
*..
.*.
**.
..*
*..
3 4
....
..*.
....
*...
....
....
3 5
.**..
.***.
..**.
***..
.**..
**...
Hint
[Sample Explanation #1]
All possible cases:

[Constraints]
| Subtask | Points | Constraints and Notes |
|---|---|---|
| None |
For of the testdata, .
[Notes]
The scoring for this problem follows the original COCI problem, with a full score of .
Translated from COCI2020-2021 CONTEST #3 T3 Sateliti.
Translated by ChatGPT 5
京公网安备 11011102002149号