結果

問題 No.2183 LCA on Rational Tree
ユーザー tailstails
提出日時 2023-01-17 19:40:46
言語 cLay
(20240104-1)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 7,086 ms
コンパイル使用メモリ 221,140 KB
実行使用メモリ 10,688 KB
最終ジャッジ日時 2023-08-30 22:52:51
合計ジャッジ時間 8,229 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
10,612 KB
testcase_01 AC 31 ms
10,516 KB
testcase_02 AC 45 ms
10,564 KB
testcase_03 AC 27 ms
10,640 KB
testcase_04 AC 14 ms
10,688 KB
testcase_05 AC 31 ms
10,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

struct S{
	ll p,q,l,n,f[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){
			ll 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