結果
問題 |
No.1577 織姫と彦星2
|
ユーザー |
👑 ![]() |
提出日時 | 2021-06-29 19:09:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 260 ms / 2,000 ms |
コード長 | 926 bytes |
コンパイル時間 | 964 ms |
コンパイル使用メモリ | 86,992 KB |
最終ジャッジ日時 | 2025-01-22 14:57:36 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 53 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <map> using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int N; int s,t; vector<int> st; vector<vector<int>> E; map<int,int> G; int main(){ cin >> N; st.resize(N+2); cin >> st[N] >> st[N+1]; rep(i,N) cin >> st[i]; E.resize(N+2); rep(i,N+2) G[st[i]] = i; rep(i,N+2) rep(d,30){ int to = st[i] ^ (1<<d); if(G.find(to) == G.end()) continue; E[i].push_back(G[to]); } vector<int> I = {N}; vector<int> D(N+2,-1); D[N] = 0; rep(i,I.size()){ int p = I[i]; for(int e : E[p]) if(D[e] == -1){ D[e] = D[p] + 1; I.push_back(e); } } if(D[N+1] == -1) cout << "-1\n"; else cout << (D[N+1]-1) << "\n"; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_inst;