結果

問題 No.1577 織姫と彦星2
ユーザー ansainansain
提出日時 2021-06-29 20:14:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 1,554 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 91,052 KB
最終ジャッジ日時 2023-09-08 05:25:42
合計ジャッジ時間 10,819 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,636 KB
testcase_01 AC 87 ms
71,804 KB
testcase_02 AC 88 ms
71,868 KB
testcase_03 AC 91 ms
71,712 KB
testcase_04 AC 89 ms
71,692 KB
testcase_05 AC 102 ms
77,836 KB
testcase_06 AC 103 ms
77,152 KB
testcase_07 AC 170 ms
86,544 KB
testcase_08 AC 125 ms
79,572 KB
testcase_09 AC 183 ms
90,768 KB
testcase_10 AC 113 ms
79,312 KB
testcase_11 AC 107 ms
77,900 KB
testcase_12 AC 143 ms
82,880 KB
testcase_13 AC 110 ms
78,696 KB
testcase_14 AC 146 ms
85,028 KB
testcase_15 AC 118 ms
78,476 KB
testcase_16 AC 166 ms
86,784 KB
testcase_17 AC 135 ms
80,832 KB
testcase_18 AC 100 ms
77,016 KB
testcase_19 AC 160 ms
85,252 KB
testcase_20 AC 146 ms
82,820 KB
testcase_21 AC 163 ms
86,628 KB
testcase_22 AC 153 ms
86,724 KB
testcase_23 AC 121 ms
78,968 KB
testcase_24 AC 150 ms
90,920 KB
testcase_25 AC 110 ms
78,420 KB
testcase_26 AC 118 ms
78,860 KB
testcase_27 AC 120 ms
88,220 KB
testcase_28 AC 134 ms
84,044 KB
testcase_29 AC 112 ms
81,548 KB
testcase_30 AC 119 ms
81,352 KB
testcase_31 AC 147 ms
86,700 KB
testcase_32 AC 99 ms
77,880 KB
testcase_33 AC 93 ms
77,568 KB
testcase_34 AC 113 ms
80,916 KB
testcase_35 AC 146 ms
85,396 KB
testcase_36 AC 150 ms
86,796 KB
testcase_37 AC 169 ms
91,052 KB
testcase_38 AC 175 ms
90,940 KB
testcase_39 AC 117 ms
79,476 KB
testcase_40 AC 111 ms
80,108 KB
testcase_41 AC 135 ms
89,404 KB
testcase_42 AC 115 ms
84,124 KB
testcase_43 AC 123 ms
84,108 KB
testcase_44 AC 96 ms
77,844 KB
testcase_45 AC 110 ms
77,708 KB
testcase_46 AC 101 ms
78,288 KB
testcase_47 AC 115 ms
89,284 KB
testcase_48 AC 103 ms
79,916 KB
testcase_49 AC 117 ms
80,584 KB
testcase_50 AC 109 ms
78,880 KB
testcase_51 AC 96 ms
77,592 KB
testcase_52 AC 145 ms
91,008 KB
testcase_53 AC 146 ms
90,884 KB
testcase_54 AC 112 ms
81,608 KB
testcase_55 AC 137 ms
90,840 KB
testcase_56 AC 111 ms
78,664 KB
testcase_57 AC 103 ms
77,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict, Counter, deque
from itertools import permutations, combinations, product, combinations_with_replacement, groupby, accumulate
import operator
from math import sqrt, gcd, factorial
# from math import isqrt, prod,comb  # python3.8用(notpypy)
#from bisect import bisect_left,bisect_right
#from functools import lru_cache,reduce
from heapq import heappush, heappop, heapify, heappushpop, heapreplace
#import numpy as np
#import networkx as nx
#from networkx.utils import UnionFind
#from numba import njit, b1, i1, i4, i8, f8
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, NegativeCycleError
# numba例 @njit(i1(i4[:], i8[:, :]),cache=True) 引数i4配列、i8 2次元配列,戻り値i1
def input(): return sys.stdin.readline().rstrip()
def divceil(n, k): return 1+(n-1)//k  # n/kの切り上げを返す
def yn(hantei, yes='Yes', no='No'): print(yes if hantei else no)


def main():
    n = int(input())
    s, t = map(int, input().split())
    A = list(map(int, input().split()))

    dist = {AA:-1 for AA in A}
    dist[s] = 0
    dist[t] = -1
    d=deque()
    d.append(s)
    while d:
        v = d.popleft()
        for ii in range(30):
            i = v ^ (2**ii)
            if i not in dist:
                continue
            if dist[i] != -1:
                continue
            dist[i] = dist[v] + 1
            d.append(i)

    print(-1 if dist[t]==-1 else dist[t]-1)


if __name__ == '__main__':
    main()
0