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

6267번 - Crazy Bits 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB106645559.783%

문제

Olandicans have invented a strange computer; it has only 12-bit registers to store numbers. And the only command that this computer accepts is SWAP. The Swap function is called with 3 parameters i, j, and d. A call of swap(i, j, d) swaps the jth bit of the ith register with its neighboring bit in direction d (0: up, 1: right, 2: down, 3: left). For example, swap (2, 3, 1) swaps the 3rd and the 4th bits of the 2nd register and Swap(6, 4, 2) swaps the 4th bits of the 6th and the 7th registers. Olandicans know the initial values of the registers and they want to change them to some other numbers. They asked you to help them find the minimum number of swap calls.

입력

The input consists of multiple test cases. The first line of each test case is n (1 ≤ n ≤ 16), the number of registers. The next line contains n integers, where the ith number is the initial value of the ith register. The next line contains n integers, where the ith number is the desired value of the ith register. The input is terminated by a line containing a zero.

출력

For each test case, you should write a single line containing the minimum number of swaps needed for that test case. If it is not possible, write "Impossible".

제한

예제 입력 1

2
2 3
6 2
3
1 1 1
2 3 4
4
5 2 6 0
3 2 2 4
0

예제 출력 1

3
Impossible
2

힌트

출처

ICPC > Regionals > Asia West Continent > Iran > Tehran Site 2007 I번

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

출처

대학교 대회

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

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