結果
問題 | No.2183 LCA on Rational Tree |
ユーザー |
|
提出日時 | 2023-01-08 17:51:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,028 bytes |
コンパイル時間 | 1,481 ms |
コンパイル使用メモリ | 167,624 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-15 21:16:50 |
合計ジャッジ時間 | 1,926 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 WA * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int Q; cin >> Q; while(Q--){ int p0, q0, p1, q1; cin >> p0 >> q0 >> p1 >> q1; auto ope = [&](int &p, int &q, int d){ int p2 = p0 ^ p1 ^ p, q2 = q0 ^ q1 ^ q; int d2 = q2 - p2; int di = d - p % d; if(d == d2 && p2 <= p + di){ p = p2, q = q2; return; } p += di, q += di; int g = __gcd(p, q); p /= g, q /= g; }; while(p0 != p1 || q0 != q1){ int d0 = q0 - p0; int d1 = q1 - p1; if(d0 == 1 && d1 == 1){ p0 = max(p0, p1); q0 = p0 + 1; break; } if(d0 > d1 || (d0 == d1 && p0 < p1)){ ope(p0, q0, d0); }else{ ope(p1, q1, d1); } } cout << p0 << " " << q0 << '\n'; } }