結果

問題 No.1577 織姫と彦星2
ユーザー kotatsugame
提出日時 2021-06-30 09:16:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 566 bytes
コンパイル時間 1,233 ms
コンパイル使用メモリ 85,944 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-26 11:18:29
合計ジャッジ時間 11,777 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 2 RE * 51
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
#include<map>
using namespace std;
int N;
int A[1002],d[1002];
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;
}
0