結果

問題 No.2953 Maximum Right Triangle
コンテスト
ユーザー syuya2036
提出日時 2024-11-09 02:02:47
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 307µs
コード長 958 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,065 ms
コンパイル使用メモリ 331,724 KB
実行使用メモリ 9,872 KB
最終ジャッジ日時 2026-09-21 15:45:51
合計ジャッジ時間 3,229 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e18;

long long gcd(long a, long b) {
	if(a % b == 0) return b;
	return gcd(b, a%b);
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int T; cin>>T;
    while(T--) {
        long long x, y, D;
        cin>>D>>x>>y;
        long long ans = 0;
        if(x==0) {
            cout<<y*D<<endl;
            continue;
        } else if(y == 0) {
            cout<<x*D<<endl;
            continue;
        }
        long long X = x / gcd(x, y);
        long long Y = y / gcd(x, y);
        {
            long long mt = min((D-y)/X, x/Y);
            long long i = y+mt*X;
            long long j = x-mt*Y;
            ans = max(ans, abs(x*i - y*j));
        }
        {
            long long mt = min((D-x)/Y, y/X);
            long long i = y-mt*X;
            long long j = x+mt*Y;
            ans = max(ans, abs(x*i - y*j));
        }
        cout<<ans<<endl;
    }
}

0