結果

問題 No.2953 Maximum Right Triangle
ユーザー haihamabossu
提出日時 2024-11-08 21:53:47
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 200,092 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 21:54:00
合計ジャッジ時間 2,632 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
void solve() {
ll d, x, y;
cin >> d >> x >> y;
if (x == 0 || y == 0) {
cout << max(x, y) * d << '\n';
return;
}
auto calc = [&](ll xi, ll yi) -> ll {
ll res = (xi < x ? x * yi : xi * y) * 2;
res -= x * y;
res -= xi * yi;
res -= abs(x - xi) * abs(yi - y);
return res;
};
ll g = __gcd(x, y);
ll dx = y / g, dy = -(x / g);
ll ans = 0;
{
ll k = min(x / dx, (d - y) / abs(dy));
if (k > 0) {
ans = max(ans, calc(x - dx * k, y - dy * k));
}
}
{
ll k = min((d - x) / dx, y / abs(dy));
if (k > 0) {
ans = max(ans, calc(x + dx * k, y + dy * k));
}
}
cout << ans << '\n';
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
int T = 1;
cin >> T;
for (int t = 0; t < T; t++) {
solve();
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0