結果
| 問題 | No.1576 織姫と彦星 |
| ユーザー |
C
|
| 提出日時 | 2026-09-30 23:33:30 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1 ms / 2,000 ms |
| + 789µs | |
| コード長 | 1,141 bytes |
| 記録 | |
| コンパイル時間 | 7,748 ms |
| コンパイル使用メモリ | 401,300 KB |
| 実行使用メモリ | 9,920 KB |
| 最終ジャッジ日時 | 2026-09-30 23:33:41 |
| 合計ジャッジ時間 | 10,326 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 54 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
using ll=long long;
using ld=long double;
using vll=vector<ll>;
using vvll=vector<vll>;
using pll=pair<ll,ll>;
// using mint=modint;
// template<class K,class V>
// using ordered_map=tree<K,V,less<K>,rb_tree_tag,tree_order_statistics_node_update>;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N;
cin>>N;
vll stone(N+2);
for(int i=0;i<N+2;++i)cin>>stone[i];
unordered_map<ll,ll>id;
for(int i=0;i<N+2;++i)id[stone[i]]=i;
vll d(N+2,-1);
queue<ll>q;
d[0]=0;
q.push(0);
while(!q.empty()){
ll u=q.front();
ll y=stone[u];
q.pop();
for(int b=0;b<30;++b){
ll x=y^(1LL<<b);
if(id.count(x)){
ll v=id[x];
if(d[v]==-1){
d[v]=d[u]+1;
q.push(v);
}
}
}
}
if(d[1]==-1)cout<<-1<<endl;
else cout<<d[1]-1<<endl;
}
C