結果

問題 No.1576 織姫と彦星
ユーザー erbowlerbowl
提出日時 2022-09-18 17:29:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 3,474 bytes
コンパイル時間 3,179 ms
コンパイル使用メモリ 215,940 KB
実行使用メモリ 5,008 KB
最終ジャッジ日時 2023-08-23 18:14:01
合計ジャッジ時間 5,090 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 5 ms
4,384 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 7 ms
4,712 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 7 ms
5,008 KB
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 5 ms
4,376 KB
testcase_40 AC 4 ms
4,380 KB
testcase_41 AC 4 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 3 ms
4,376 KB
testcase_44 AC 8 ms
4,916 KB
testcase_45 AC 3 ms
4,376 KB
testcase_46 AC 7 ms
4,576 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 4 ms
4,496 KB
testcase_49 AC 5 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 6 ms
4,544 KB
testcase_54 AC 4 ms
4,376 KB
testcase_55 AC 4 ms
4,380 KB
testcase_56 AC 4 ms
4,380 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long

// modint
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() const { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept {
        is >> x.val;
        x.val %= MOD;
        if (x.val < 0) x.val += MOD;
        return is;
    }
    friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD>& r, long long n) noexcept {
        if (n == 0) return 1;
        if (n < 0) return modpow(modinv(r), -n);
        auto t = modpow(r, n / 2);
        t = t * t;
        if (n & 1) t = t * r;
        return t;
    }
    friend constexpr Fp<MOD> modinv(const Fp<MOD>& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        return Fp<MOD>(u);
    }
};

// const int MOD = 1000000007;
//const int MOD = 998244353;
// using mint = Fp<MOD>;


signed main(){
    ll n;
    std::cin >> n;
    ll st,en;
    std::cin >> st>>en;
    map<ll,ll> d;
    map<ll,bool> al;
    for (int i = 0; i < n; i++) {
        ll tmp;
        std::cin >> tmp;
        al[tmp] = true;
    }
    al[en] = true;
    
    d[st] = 0;
    
    queue<ll> q;
    q.push(st);
    while(!q.empty()){
        auto now = q.front();q.pop();
        for (int i = 0; i < 30; i++) {
            if(al[now^(1ll<<i)]){
                if(d[now^(1ll<<i)]==0){
                    d[now^(1ll<<i)] = d[now]+1;
                    // std::cout << d[now^(1ll<<i)]<<" "<<i<<" "<<now<<" "<< (now^(1ll<<i))<< std::endl;
                    q.push(now^(1ll<<i));
                }
            }
        }
    }
    // if(d[en]==0){
    //     std::cout << -1 << std::endl;
    // }else{
        std::cout << d[en]-1 << std::endl;
    // }
}
0