結果
問題 |
No.2953 Maximum Right Triangle
|
ユーザー |
|
提出日時 | 2024-11-10 14:37:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 770 bytes |
コンパイル時間 | 2,009 ms |
コンパイル使用メモリ | 193,192 KB |
最終ジャッジ日時 | 2025-02-25 03:28:09 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 6 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ ll D, x, y, ans = 0; cin >> D >> x >> y; auto calc = [&](ll x2, ll y2){ ans = max(ans, abs(x * y2 - y * x2)); }; ll g = gcd(x, y); if(g == 0){ cout << 0 << '\n'; continue; } if(x == 0 || y == 0){ cout << max(x, y) * D << '\n'; continue; } ll dx = y / g, dy = x / g; ll d = min(x / dx, (D - y) / dy); calc(x - dx * d, y + dy * d); d = min((D - x) / dx, y / dy); calc(x + dx * d, y - dy * d); cout << ans << '\n'; } }