結果

問題 No.2183 LCA on Rational Tree
ユーザー tailstails
提出日時 2023-01-17 19:52:12
言語 cLay
(20240104-1)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 537 bytes
コンパイル時間 7,510 ms
コンパイル使用メモリ 221,512 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-06-10 22:22:29
合計ジャッジ時間 8,090 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
8,448 KB
testcase_01 AC 26 ms
8,448 KB
testcase_02 AC 41 ms
8,576 KB
testcase_03 AC 23 ms
8,576 KB
testcase_04 AC 13 ms
8,576 KB
testcase_05 AC 27 ms
8,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

struct S{
	unsigned p,q,l,n,f[32],e[32];
	S(){
		rd(p,q);
		n=Factor(q-=p,f);
		l=0;
	}
	void step(){
		p+=l;
		rep[f](x,n){
			while(p%x==0&&q%x==0){
				p/=x;
				q/=x;
			}
		}
		l=1<<30;
		rep[f](x,n){
			if(q%x==0){
				l<?=x-p%x;
			}
		}
	}
};

bool h(S&u,S&v){
	if(u.p<=v.p<u.p+u.l){
		wt(v.p,v.p+v.q);
		return true;
	}
	return false;
}

{
	ll@q;
	rep(q){
		S u,v;
		while(1){
			int d=v.q-u.q;
			if(d==0){
				if(h(u,v)||h(v,u)){
					break;
				}
			}
			if(d<=0){
				u.step();
			}
			if(d>=0){
				v.step();
			}
		}
	}
}
0