시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 216 72 50 31.447%

문제

길이가 같은 두 문자열 S와 T가 주어진다. S를 이루는 문자는 '0', '1', '?' 이고, T는 '0', '1' 이다. S를 T로 바꾸는데 필요한 연산 횟수의 최솟값을 구하는 프로그램을 작성하시오.

사용할 수 있는 연산은 다음과 같다.

  1. S의 '0'를 '1'로 바꾸기
  2. S의 '?'를 '0'이나 '1'로 바꾸기
  3. S의 두 문자의 위치를 바꾸기

예를 들어, S = "01??00"이고 T = "001010"인 경우 3번 만에 S를 T로 바꿀 수 있다.

  • S = "01??00"
  • S[2]를 '1'로 바꾼다. (S = "011?00")
  • S[3]를 '0'로 바꾼다. (S = "011000")
  • S[1]와 S[4]의 위치를 바꾼다. (S = "001010")

입력

첫째 줄에 테스트 케이스의 개수 C (C ≤ 200)가 주어진다. 각 테스트 케이스는 두 줄로 이루어져 있다. 첫째 줄에는 '0', '1', '?'로 이루어진 S, 둘째 줄에는 '0', '1'로 이루어진 T가 주어진다. 두 문자열의 길이는 100을 넘지 않으며, 빈 문자열이 아니다.

출력

각 테스트 케이스마다, S를 T로 바꾸는데 필요한 연산 횟수의 최솟값을 출력한다. 만약, S를 T로 바꿀 수 없다면, -1을 출력한다.

예제 입력 1

3
01??00
001010
01
10
110001
000000

예제 출력 1

Case 1: 3
Case 2: 1
Case 3: -1
W3sicHJvYmxlbV9pZCI6IjM4MDYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJTXHViOTdjIFRcdWI4NWMiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YWUzOFx1Yzc3NFx1YWMwMCBcdWFjMTlcdWM3NDAgXHViNDUwIFx1YmIzOFx1Yzc5MFx1YzVmNCBTXHVjNjQwIFRcdWFjMDAgXHVjOGZjXHVjNWI0XHVjOWM0XHViMmU0LiBTXHViOTdjIFx1Yzc3NFx1YjhlOFx1YjI5NCBcdWJiMzhcdWM3OTBcdWIyOTQgJiMzOTswJiMzOT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