Logo
(追記) (追記ここまで)

18531번 - Letter Wheels 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) (하단 참고)512 MB150635340.152%

문제

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.

제한

예제 입력 1

ABC
ABC
ABC

예제 출력 1

2

예제 입력 2

ABBBAAAA
BBBCCCBB
CCCCAAAC

예제 출력 2

3

예제 입력 3

AABB
BBCC
ACAC

예제 출력 3

-1

힌트

출처

ICPC > Regionals > North America > North America Championship > North America Championship 2020 H번

Contest > Open Cup > 2019/2020 Season > Stage 13: Grand Prix of America H번

시간 제한

  • PyPy3: 12 초
  • PyPy2: 12 초
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /