結果
| 問題 | 
                            No.1576 織姫と彦星
                             | 
                    
| ユーザー | 
                             sugar_sentan
                         | 
                    
| 提出日時 | 2021-06-20 16:23:17 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 557 bytes | 
| コンパイル時間 | 177 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 19,236 KB | 
| 最終ジャッジ日時 | 2024-06-22 22:28:45 | 
| 合計ジャッジ時間 | 3,867 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 2 TLE * 1 -- * 51 | 
ソースコード
def checkhamming(n, m):
    return bin(n ^ m).count('1')
N = int(input())
start, end = map(int, input().split())
stones = list(map(int, input().split()))
stones.append(end)
q = [[start, 0]]
while len(q):
    # print(q)
    now, count = q.pop(0)
    if count > len(stones)+1:
        break
    # print(now, count)
    for stone in stones:
        if checkhamming(now, stone) <= 1 and now != stone:
            if stone == end:
                print(count)
                exit()
            else:
                q.append([stone, count+1])
    
print(-1)
            
            
            
        
            
sugar_sentan