結果
問題 | No.2953 Maximum Right Triangle |
ユーザー |
|
提出日時 | 2024-11-09 04:20:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 868 bytes |
コンパイル時間 | 1,988 ms |
コンパイル使用メモリ | 167,592 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-09 04:20:22 |
合計ジャッジ時間 | 3,003 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 6 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int,int> P;#define REP(i,n) for(int i=0;i<int(n);i++)ll gcd(ll a,ll b){if(b==0) return a;else return gcd(b,a%b);}int main(void){cin.tie(nullptr); ios_base::sync_with_stdio(false);ll i,j;int T;cin >> T;while(T--){ll D,a,b;cin >> D >> a >> b;if(a==0){cout << b*D << endl;continue;}if(b==0){cout << a*D << endl;continue;}ll p,q;if(a*a+b*b>D*b) p=(a*a+b*b-D*b+a-1)/a;else p=0;if(a*a+b*b>D*a) q=D;else q=(a*a+b*b)/a;ll d=b/gcd(a,b);ll X=a+(q-a)/d*d;ll Y=(-a*X+a*a+b*b)/b;ll s=2*max(a,X)*max(b,Y)-(a*b+X*Y+llabs(X-a)*llabs(Y-b));X=a-(a-p)/d*d;Y=(-a*X+a*a+b*b)/b;ll S=2*max(a,X)*max(b,Y)-(a*b+X*Y+llabs(X-a)*llabs(Y-b));cout << max(s,S) << endl;}return 0;}