結果

問題 No.2594 Mix shake!!
ユーザー hitonanodehitonanode
提出日時 2023-12-04 02:44:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 437 ms / 2,000 ms
コード長 2,658 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2023-12-20 01:04:53
合計ジャッジ時間 13,958 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,880 KB
testcase_01 AC 33 ms
10,880 KB
testcase_02 AC 32 ms
10,880 KB
testcase_03 AC 33 ms
10,880 KB
testcase_04 AC 32 ms
10,880 KB
testcase_05 AC 32 ms
10,880 KB
testcase_06 AC 34 ms
10,880 KB
testcase_07 AC 33 ms
10,880 KB
testcase_08 AC 33 ms
10,880 KB
testcase_09 AC 33 ms
10,880 KB
testcase_10 AC 33 ms
10,880 KB
testcase_11 AC 33 ms
10,880 KB
testcase_12 AC 34 ms
10,880 KB
testcase_13 AC 34 ms
10,880 KB
testcase_14 AC 35 ms
10,880 KB
testcase_15 AC 35 ms
10,880 KB
testcase_16 AC 33 ms
10,880 KB
testcase_17 AC 33 ms
10,880 KB
testcase_18 AC 34 ms
10,880 KB
testcase_19 AC 34 ms
10,880 KB
testcase_20 AC 33 ms
10,880 KB
testcase_21 AC 33 ms
10,880 KB
testcase_22 AC 33 ms
10,880 KB
testcase_23 AC 34 ms
10,880 KB
testcase_24 AC 33 ms
10,880 KB
testcase_25 AC 32 ms
10,880 KB
testcase_26 AC 33 ms
10,880 KB
testcase_27 AC 33 ms
10,880 KB
testcase_28 AC 34 ms
10,880 KB
testcase_29 AC 33 ms
10,880 KB
testcase_30 AC 33 ms
10,880 KB
testcase_31 AC 33 ms
10,880 KB
testcase_32 AC 51 ms
10,880 KB
testcase_33 AC 66 ms
11,008 KB
testcase_34 AC 408 ms
11,136 KB
testcase_35 AC 393 ms
11,136 KB
testcase_36 AC 395 ms
11,136 KB
testcase_37 AC 437 ms
11,136 KB
testcase_38 AC 392 ms
11,136 KB
testcase_39 AC 385 ms
11,136 KB
testcase_40 AC 390 ms
11,136 KB
testcase_41 AC 396 ms
11,136 KB
testcase_42 AC 393 ms
11,136 KB
testcase_43 AC 393 ms
11,136 KB
testcase_44 AC 398 ms
11,136 KB
testcase_45 AC 387 ms
11,136 KB
testcase_46 AC 387 ms
11,136 KB
testcase_47 AC 390 ms
11,136 KB
testcase_48 AC 394 ms
11,136 KB
testcase_49 AC 397 ms
11,136 KB
testcase_50 AC 389 ms
11,136 KB
testcase_51 AC 388 ms
11,136 KB
testcase_52 AC 389 ms
11,136 KB
testcase_53 AC 389 ms
11,136 KB
testcase_54 AC 35 ms
10,880 KB
testcase_55 AC 34 ms
10,880 KB
testcase_56 AC 32 ms
10,880 KB
testcase_57 AC 33 ms
10,880 KB
testcase_58 AC 33 ms
10,880 KB
testcase_59 AC 32 ms
10,880 KB
testcase_60 AC 33 ms
10,880 KB
testcase_61 AC 33 ms
10,880 KB
testcase_62 AC 33 ms
10,880 KB
testcase_63 AC 33 ms
10,880 KB
testcase_64 AC 32 ms
10,880 KB
testcase_65 AC 33 ms
10,880 KB
testcase_66 AC 35 ms
10,880 KB
testcase_67 AC 33 ms
10,880 KB
testcase_68 AC 36 ms
10,880 KB
testcase_69 AC 35 ms
10,880 KB
testcase_70 AC 37 ms
10,880 KB
testcase_71 AC 37 ms
10,880 KB
testcase_72 AC 32 ms
10,880 KB
testcase_73 AC 32 ms
10,880 KB
testcase_74 AC 33 ms
10,880 KB
testcase_75 AC 33 ms
10,880 KB
testcase_76 AC 32 ms
10,880 KB
testcase_77 AC 32 ms
10,880 KB
testcase_78 AC 33 ms
10,880 KB
testcase_79 AC 33 ms
10,880 KB
testcase_80 AC 36 ms
10,880 KB
testcase_81 AC 34 ms
10,880 KB
testcase_82 AC 36 ms
10,880 KB
testcase_83 AC 33 ms
10,880 KB
testcase_84 AC 34 ms
10,880 KB
testcase_85 AC 33 ms
10,880 KB
testcase_86 AC 33 ms
10,880 KB
testcase_87 AC 34 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# これはちゃんと AC のはず
from fractions import Fraction


def make_convex_slope(A: list[int], B: list[int]) -> list[tuple[int, int]]:
    x, y = 0, 0
    ret: list[tuple[int, int]] = [(0, 0)]
    seq = sorted([(Fraction(b, a), a, b) for a, b in zip(A, B)])

    for _, a, b in seq:
        x += a
        y += b
        ret.append((x, y))

    return ret


def trajectory_solve(
    A: list[int], B: list[int], C: list[int], D: list[int]
) -> tuple[bool, list[tuple[Fraction, Fraction]]]:

    assert len(A) == len(B) == len(C) == len(D)
    assert sum(A) == sum(C)
    assert sum(B) == sum(D)
    assert min(A + B + C + D) >= 1
    assert max(A + B + C + D) <= 100000000000000000

    lo_polyline = make_convex_slope(A, B)
    hi_polyline = make_convex_slope(C, D)

    for (x0, y0), (x1, y1) in zip(lo_polyline, lo_polyline[1:]):
        for x, y in hi_polyline:
            if (x1 - x0) * (y - y0) - (y1 - y0) * (x - x0) < 0:
                return False, []

    assert lo_polyline[0] == hi_polyline[0] == (0, 0)
    assert lo_polyline[-1] == hi_polyline[-1] == (sum(A), sum(B))

    nx, ny = Fraction(0), Fraction(0)

    trajectory: list[tuple[Fraction, Fraction]] = [(nx, ny)]

    while (nx, ny) != lo_polyline[-1]:
        s = Fraction(1 << 60)  # slope

        for px, py in hi_polyline:
            if px <= nx:
                continue
            s = min(s, Fraction(py - ny, px - nx))

        assert s < Fraction(1 << 60)

        next_x = Fraction(sum(A))

        for (px, py), (qx, qy) in zip(lo_polyline, lo_polyline[1:]):
            s2 = Fraction(qy - py, qx - px)

            if s2 <= s:
                continue

            # y = s * (x - nx) + ny と y = s2 * (x - px) + py の交点
            # sx - s nx + ny == s2 x - s2 px + py
            # (s - s2) x == s nx - ny - s2 px + py

            next_x = min(next_x, (s * nx - ny - s2 * px + py) / (s - s2))

        ny += s * (next_x - nx)
        nx = next_x

        trajectory.append((nx, ny))

    ans: bool = False

    if len(trajectory) - 1 < len(A):
        ans = True
    else:
        abidx = sorted([(Fraction(B[i], A[i]), i) for i in range(len(A))])
        cdidx = sorted([(Fraction(D[i], C[i]), i) for i in range(len(B))])
        if [i for _, i in abidx] == [i for _, i in cdidx]:
            ans = True

    return ans, trajectory


if __name__ == "__main__":
    input()
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    D = list(map(int, input().split()))

    ret, trajectory = trajectory_solve(A=A, B=B, C=C, D=D)

    print("Yes" if ret else "No")
0