結果
問題 |
No.1577 織姫と彦星2
|
ユーザー |
|
提出日時 | 2021-06-30 09:17:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 212 ms / 2,000 ms |
コード長 | 568 bytes |
コンパイル時間 | 861 ms |
コンパイル使用メモリ | 86,744 KB |
実行使用メモリ | 6,144 KB |
最終ジャッジ日時 | 2024-06-26 11:18:53 |
合計ジャッジ時間 | 5,681 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 53 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 8 | main() | ^~~~
ソースコード
#include<iostream> #include<queue> #include<map> using namespace std; int N; int A[50002],d[50002]; map<int,int>id; main() { cin>>N>>A[0]; cin>>A[N+1]; for(int i=1;i<=N;i++)cin>>A[i]; for(int i=0;i<=N+1;i++) { id[A[i]]=i; d[i]=1e9; } queue<int>P; P.push(0); d[0]=0; while(!P.empty()) { int u=P.front();P.pop(); for(int x=0;x<30;x++) { int v=A[u]^1<<x; if(id.find(v)!=id.end()) { int j=id[v]; if(d[j]>d[u]+1) { d[j]=d[u]+1; P.push(j); } } } } int ans=d[N+1]; if(ans==(int)1e9)ans=0; cout<<ans-1<<endl; }