結果

問題 No.1576 織姫と彦星
ユーザー 👑 tails
提出日時 2021-06-29 14:57:29
言語 cLay
(20250308-1 + boost 1.89.0)
コンパイル:
clayc _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 681 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,969 ms
コンパイル使用メモリ 203,316 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-27 00:03:43
合計ジャッジ時間 3,763 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

{
	VI nodes[32];
	map<int,VI> edges;
	set<int> vis;

	ll@n,@st,@ed;
	nodes[__builtin_popcountl(st)].push_back(st);
	nodes[__builtin_popcountl(ed)].push_back(ed);
	rep(n){
		ll@s;
		nodes[__builtin_popcountl(s)].push_back(s);
	}
	rep(i,31){
		for(ll j:nodes[i]){
			for(ll k:nodes[i+1]){
				if(__builtin_popcount(j^k)==1){
					edges[j].push_back(k);
					edges[k].push_back(j);
				}
			}
		}
	}
	int q[3000];
	ll qr=0,qw=0,ans=0;
	q[qw++]=st;
	while(qr<qw){
		ll qn=qw;
		while(qr<qn){
			ll s=q[qr++];
			if(s==ed){
				wt(ans-1);
				exit(0);
			}
			for(ll j:edges[s]){
				if(vis.find(j)==vis.end()){
					vis.insert(j);
					q[qw++]=j;
				}
			}
		}
		++ans;
	}
	wt(-1);
}
0