結果
問題 | No.1577 織姫と彦星2 |
ユーザー |
![]() |
提出日時 | 2021-07-18 19:55:45 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 717 ms / 2,000 ms |
コード長 | 1,087 bytes |
コンパイル時間 | 1,778 ms |
コンパイル使用メモリ | 145,024 KB |
実行使用メモリ | 66,560 KB |
最終ジャッジ日時 | 2024-07-08 13:47:52 |
合計ジャッジ時間 | 9,458 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 53 |
ソースコード
#include <cassert> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <limits.h> #include <map> #include <queue> #include <set> #include <string.h> #include <vector> using namespace std; typedef long long ll; struct Node { int v; int dist; Node(int v = -1, int dist = -1) { this->v = v; this->dist = dist; } }; int main() { int N; cin >> N; int start, end; cin >> start >> end; map<int, bool> exists; exists[start] = true; exists[end] = true; for (int i = 0; i < N; ++i) { int s; cin >> s; exists[s] = true; } queue<Node> que; que.push(Node(start, 0)); map<int, bool> visited; while (not que.empty()) { Node node = que.front(); que.pop(); if (visited[node.v]) continue; visited[node.v] = true; if (node.v == end) { cout << node.dist - 1 << endl; return 0; } for (int i = 0; i < 32; ++i) { int v1 = node.v ^ (1 << i); if (exists[v1]) { que.push(Node(v1, node.dist + 1)); } } } cout << -1 << endl; return 0; }