結果

問題 No.2594 Mix shake!!
ユーザー 👑 rin204
提出日時 2023-12-26 23:09:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 2,487 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 90,044 KB
最終ジャッジ日時 2024-09-27 15:18:10
合計ジャッジ時間 19,507 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 85
権限があれば一括ダウンロードができます

ソースコード

diff #

import fractions

n = int(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()))

X_ind = sorted(range(n), key=lambda i: fractions.Fraction(A[i], B[i]))
Y_ind = sorted(range(n), key=lambda i: fractions.Fraction(C[i], D[i]))

S = [(fractions.Fraction(0), fractions.Fraction(0))]
for i in X_ind:
    S.append((S[-1][0] + A[i], S[-1][1] + B[i]))
T = [(fractions.Fraction(0), fractions.Fraction(0))]
for i in Y_ind:
    T.append((T[-1][0] + C[i], T[-1][1] + D[i]))


def cross3(a, b, c):
    return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])


def iscross(a1, a2, b1, b2):
    flg1 = cross3(a1, a2, b1) * cross3(a1, a2, b2) < 0
    flg2 = cross3(b1, b2, a1) * cross3(b1, b2, a2) < 0
    return flg1 and flg2


if fractions.Fraction(*S[1]) > fractions.Fraction(*T[1]):
    print("No")
    exit()


for i in range(n + 1):
    for j in range(n):
        res = cross3(S[j], S[j + 1], T[i])
        if res > 0:
            print("No")
            exit()


def f(P1, P2):
    y1, x1 = P1
    y2, x2 = P2
    a = (y1 - y2) / (x1 - x2)
    b = y1 - a * x1
    return a, b


cnt = 1
p = 0
p2 = 1
y = fractions.Fraction(0)
x = fractions.Fraction(0)
# print(T)
# print(S)
while p < n:
    # print("+++", cnt, y, x, p, p2)
    res = cross3((y, x), T[p], T[p + 1])
    if res >= 0:
        p += 1
        continue
    cnt += 1

    while 1:
        # print(y, x, p, p2, T[p])
        # print(S[p2], S[p2 + 1])
        r1 = cross3((y, x), T[p], S[p2])
        r2 = cross3((y, x), T[p], S[p2 + 1])
        # print(p, p2, r1, r2)
        if r1 * r2 <= 0:
            break
        p2 += 1

    a, b = f((y, x), T[p])
    c, d = f(S[p2], S[p2 + 1])
    # print(y, x, T[p], S[p2], S[p2 + 1])
    # print(a, b, c, d)
    if a == c:
        y, x = S[p2 + 1]
    else:
        y = (a * d - b * c) / (a - c)
        x = (d - b) / (a - c)

    p += 1
    p2 += 1


if cnt < n:
    print("Yes")
    exit()

for i in range(n):
    for j in range(i + 1, n):
        if (fractions.Fraction(A[i], B[i]) > fractions.Fraction(A[j], B[j])) and (
            fractions.Fraction(C[i], D[i]) < fractions.Fraction(C[j], D[j])
        ):
            print("No")
            exit()

        if (fractions.Fraction(A[i], B[i]) < fractions.Fraction(A[j], B[j])) and (
            fractions.Fraction(C[i], D[i]) > fractions.Fraction(C[j], D[j])
        ):
            print("No")
            exit()


print("Yes")
0