結果

問題 No.2953 Maximum Right Triangle
コンテスト
ユーザー ripity
提出日時 2024-11-08 21:30:18
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 0 ms / 2,000 ms
コード長 558 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,022 ms
コンパイル使用メモリ 214,232 KB
実行使用メモリ 7,220 KB
最終ジャッジ日時 2026-07-06 03:17:56
合計ジャッジ時間 1,888 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

void solve() {
  ll D, x, y;
  cin >> D >> x >> y;

  if(x == 0 && y == 0) {
    cout << 0 << endl;
  }
  else if(x == 0) {
    cout << y * D << endl;
  }
  else if(y == 0) {
    cout << x * D << endl;
  }
  else {
    if(x < y) swap(x, y);
    const ll g = gcd(x, y);
    const ll p = x / g;
    const ll q = y / g;
    const ll a = x / q;
    const ll b = (D - y) / p;
    cout << (p * p + q * q) * g * min(a, b) << endl;
  }
}

int main() {
  int T;
  cin >> T;
  while(T--) solve();
}
0