|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|3 초 (추가 시간 없음)||512 MB||12||8||7||63.636%|
There are three horizontal wheels of letters stacked one on top of the other, all with the same number of columns. All wheels have one letter, either ‘A’, ‘B’ or ‘C’, in each of its columns on the edge of the wheel. You may rotate the wheels to adjust the positions of the letters. In a single rotation, you can rotate any single wheel to the right or to the left by one column. The wheels are round, of course, so the first column and last column are adjacent.
You would like to determine whether it is possible to rotate the wheels so that every column has three distinct letters across the three wheels, and if so, determine the minimum number of rotations required.
The input has exactly three lines. Each line has a string s (2 ≤ |s| ≤ 5 · 103) consisting only of upper-case letters ‘A’, ‘B’ or ‘C’, describing the letters of one wheel in their initial positions. All three strings will be of the same length.
Output a single integer, which is the minimum number of rotations required, or −1 if it isn’t possible.
ABC ABC ABC
ABBBAAAA BBBCCCBB CCCCAAAC
AABB BBCC ACAC
아래 적혀있지 않은 시간 제한은 언어 도움말에 적혀있는 기준을 따른다.