#P6681. [CCO 2019] Bad Codes
[CCO 2019] Bad Codes
Description
There are strings, each of length at most .
The strings can be concatenated in any way.
If it is possible to obtain two identical strings by concatenating strings in two different ways, output the minimum possible length of such a string. Otherwise, output -1.
Input Format
The first line contains two integers .
The next lines each contain one string of length at most .
Output Format
If it is possible to obtain two identical strings by concatenating strings in two different ways, output the minimum possible length of such a string. Otherwise, output -1.
4 3
101
10
1
100
3
4 4
1011
1000
1111
1001
-1
Hint
Explanation for Sample 1.
Concatenating the second string and the third string can produce the first string.
Constraints
For of the testdata, it is guaranteed that . None of the input strings is empty, and every input character is in .
| Subtask | Special restriction | Score | ||
|---|---|---|---|---|
| 1 | None. | |||
| 2 | No special restrictions. | Each string contains exactly one 1, such as 00100. |
||
| 3 | None. | |||
Notes
This problem is translated from Canadian Computing Olympiad 2019 Day 2 T3 Bad Codes.
Translated by ChatGPT 5
京公网安备 11011102002149号