結果
問題 | No.2953 Maximum Right Triangle |
ユーザー |
|
提出日時 | 2024-11-10 02:23:15 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 768 bytes |
コンパイル時間 | 1,029 ms |
コンパイル使用メモリ | 101,112 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-10 02:23:16 |
合計ジャッジ時間 | 1,501 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 6 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <numeric>using namespace std;typedef long long ll;#define rep(i,a,n) for(int i=(a);i<(n);i++)int T;long D, x, y;int main(){ios::sync_with_stdio(false);cin.tie(nullptr);cin >> T;while(T--){cin >> D >> x >> y;long g = gcd(x, y);long nx = y/g, ny = -x/g;long l=0L, r=1e9+1;while(l+1<r){long mid = (l+r)/2;long xx = mid*nx+x, yy = mid*ny+y;if(0<=xx&&xx<=D&&0<=yy&&yy<=D) l = mid;else r = mid;}long L=-1e9-1, R=0L;while(L+1<R){long mid = (L+R)/2;long xx = mid*nx+x, yy = mid*ny+y;if(0<=xx&&xx<=D&&0<=yy&&yy<=D) R = mid;else L = mid;}if(abs(l)>abs(R)) cout << (x*x+y*y)/g*l << endl;else cout << -(x*x+y*y)/g*R << endl;}}