結果
問題 | No.2953 Maximum Right Triangle |
ユーザー |
|
提出日時 | 2024-11-16 01:02:53 |
言語 | Fortran (gFortran 14.2.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,661 bytes |
コンパイル時間 | 1,611 ms |
コンパイル使用メモリ | 32,256 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-16 01:02:56 |
合計ジャッジ時間 | 1,170 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 6 |
ソースコード
!> This file was processed by `fypp`.!> Today's fortune: "Lucky:)", really OK?!> ランダムウォーク猿「'重実装' で はっぴー.」program f902953use, intrinsic :: iso_fortran_env!> auto use moduleimplicit noneinteger(int32) :: tinteger(int32) :: iread(input_unit, *) tdo i = 1, tcall solve()end docontainsimpure subroutine solve()integer(int64) :: d, x, yinteger(int64) :: g, nx, nyread(input_unit, *) d, x, yif (x == 0) thenwrite(output_unit, '(i0)') y * dreturnelse if (y == 0) thenwrite(output_unit, '(i0)') x * dreturnend if!> (nx, ny) == (y, -x) /g ベクトルは (x, y) ベクトルに垂直.g = gcd(x, y)nx = y / gny = - x / gblock!> (x, y)!> nx >= 0.!> x + t * nx <= d.integer(int64) :: ansinteger(int64) :: bx, byinteger(int64) :: n_dist_sqn_dist_sq = nx ** 2 + ny ** 2ans = 0_int64if (nx < 0) thennx = - nxny = - nyend ifassociate(t => (d - x) / nx)!> x + t * nx <= dif (t > 0) thenbx = x + t * nxby = y + t * nyif (0 <= by .and. by <= d) thenans = max(ans, t * g * n_dist_sq)end ifend ifend associateassociate(t => x / nx)!> x - t * nx >= 0if (t > 0) thenbx = x - t * nxby = y - t * nyif (0 <= by .and. by <= d) thenans = max(ans, t * g * n_dist_sq)end ifend ifend associateif (ny < 0) thennx = - nxny = - nyend ifassociate(t => (d - y) / ny)!> y + t * ny <= dif (t > 0) thenbx = x + t * nxby = y + t * nyif (0 <= bx .and. bx <= d) thenans = max(ans, t * g * n_dist_sq)end ifend ifend associateassociate(t => y / ny)!> y - t * ny >= 0if (t > 0) thenbx = x - t * nxby = y - t * nyif (0 <= bx .and. bx <= d) thenans = max(ans, t * g * n_dist_sq)end ifend ifend associatewrite(output_unit, '(i0)') ansend blockend subroutine solvepure integer(int64) function gcd(a, b) result(res)integer(int64), intent(in) :: a, binteger(int64) :: arr(1:2)arr(1:2) = [max(abs(a), abs(b)), min(abs(a), abs(b))]do while (arr(2) /= 0)arr(1:2) = [arr(2), mod(arr(1), arr(2))]end dores = arr(1)end function gcdend program f902953