結果

問題 No.1577 織姫と彦星2
ユーザー 沙耶花沙耶花
提出日時 2021-06-30 08:10:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 720 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 210,664 KB
実行使用メモリ 5,812 KB
最終ジャッジ日時 2023-09-08 17:23:16
合計ジャッジ時間 8,873 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 10 ms
4,392 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 138 ms
5,484 KB
testcase_08 AC 37 ms
4,380 KB
testcase_09 AC 209 ms
5,776 KB
testcase_10 AC 20 ms
4,376 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 67 ms
4,764 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 70 ms
5,156 KB
testcase_15 AC 30 ms
4,380 KB
testcase_16 AC 129 ms
5,172 KB
testcase_17 AC 58 ms
4,604 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 104 ms
5,124 KB
testcase_20 AC 90 ms
4,892 KB
testcase_21 AC 125 ms
5,012 KB
testcase_22 AC 114 ms
5,164 KB
testcase_23 AC 38 ms
4,376 KB
testcase_24 AC 120 ms
5,812 KB
testcase_25 AC 20 ms
4,376 KB
testcase_26 AC 37 ms
4,376 KB
testcase_27 AC 38 ms
5,400 KB
testcase_28 AC 75 ms
4,992 KB
testcase_29 AC 28 ms
4,560 KB
testcase_30 AC 45 ms
4,732 KB
testcase_31 AC 106 ms
5,196 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 32 ms
4,460 KB
testcase_35 AC 109 ms
4,940 KB
testcase_36 AC 100 ms
5,304 KB
testcase_37 AC 192 ms
5,488 KB
testcase_38 AC 170 ms
5,804 KB
testcase_39 AC 49 ms
4,380 KB
testcase_40 AC 35 ms
4,400 KB
testcase_41 AC 89 ms
5,496 KB
testcase_42 AC 30 ms
4,980 KB
testcase_43 AC 34 ms
5,008 KB
testcase_44 AC 3 ms
4,380 KB
testcase_45 AC 15 ms
4,380 KB
testcase_46 AC 12 ms
4,380 KB
testcase_47 AC 37 ms
5,440 KB
testcase_48 AC 19 ms
4,480 KB
testcase_49 AC 51 ms
4,584 KB
testcase_50 AC 25 ms
4,376 KB
testcase_51 AC 5 ms
4,376 KB
testcase_52 AC 111 ms
5,752 KB
testcase_53 AC 124 ms
5,664 KB
testcase_54 AC 31 ms
4,672 KB
testcase_55 AC 89 ms
5,644 KB
testcase_56 AC 31 ms
4,376 KB
testcase_57 AC 12 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

int main(){
	
	int N;
	cin>>N;
	
	int s,e;
	N += 2;
	cin>>s>>e;
	
	vector<int> x(N);
	x[0] = s;
	x.back() = e;
	
	rep(i,N-2){
		cin>>x[i+1];
	}
	
	map<int,int> mp;
	rep(i,N){
		mp[x[i]] = i;
	}
	
	vector<int> dis(N,Inf);
	dis[0] = 0;
	queue<int> Q;
	Q.push(0);
	
	while(Q.size()>0){
		int u = Q.front();
		Q.pop();
		
		rep(i,30){
			int v = x[u] ^ (1<<i);
			if(!mp.count(v))continue;
			int ind = mp[v];
			if(dis[ind]!=Inf)continue;
			Q.push(ind);
			dis[ind] = dis[u]+1;
		}
	}
	
	int ans = dis.back();
	
	if(ans==Inf)ans = -1;
	else ans--;
	
	cout<<ans<<endl;
	
    return 0;
}
0