結果

問題 No.2594 Mix shake!!
ユーザー rin204rin204
提出日時 2023-12-26 23:09:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 387 ms / 2,000 ms
コード長 2,487 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 89,612 KB
最終ジャッジ日時 2023-12-26 23:09:26
合計ジャッジ時間 20,357 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
87,692 KB
testcase_01 AC 144 ms
87,692 KB
testcase_02 AC 143 ms
87,564 KB
testcase_03 AC 140 ms
87,692 KB
testcase_04 AC 167 ms
87,692 KB
testcase_05 AC 140 ms
87,692 KB
testcase_06 AC 140 ms
87,692 KB
testcase_07 AC 138 ms
87,692 KB
testcase_08 AC 138 ms
87,692 KB
testcase_09 AC 137 ms
87,692 KB
testcase_10 AC 137 ms
87,692 KB
testcase_11 AC 139 ms
87,692 KB
testcase_12 AC 151 ms
87,692 KB
testcase_13 AC 145 ms
87,692 KB
testcase_14 AC 147 ms
87,692 KB
testcase_15 AC 148 ms
87,692 KB
testcase_16 AC 146 ms
87,564 KB
testcase_17 AC 143 ms
87,692 KB
testcase_18 AC 216 ms
89,356 KB
testcase_19 AC 253 ms
89,228 KB
testcase_20 AC 142 ms
87,692 KB
testcase_21 AC 145 ms
87,692 KB
testcase_22 AC 202 ms
89,356 KB
testcase_23 AC 139 ms
87,692 KB
testcase_24 AC 143 ms
87,692 KB
testcase_25 AC 145 ms
87,692 KB
testcase_26 AC 173 ms
87,692 KB
testcase_27 AC 141 ms
87,692 KB
testcase_28 AC 143 ms
87,692 KB
testcase_29 AC 139 ms
87,692 KB
testcase_30 AC 139 ms
87,692 KB
testcase_31 AC 139 ms
87,692 KB
testcase_32 AC 224 ms
89,356 KB
testcase_33 AC 258 ms
89,356 KB
testcase_34 AC 335 ms
89,356 KB
testcase_35 AC 331 ms
89,612 KB
testcase_36 AC 331 ms
89,356 KB
testcase_37 AC 355 ms
89,356 KB
testcase_38 AC 328 ms
89,484 KB
testcase_39 AC 343 ms
89,356 KB
testcase_40 AC 387 ms
89,484 KB
testcase_41 AC 328 ms
89,356 KB
testcase_42 AC 333 ms
89,356 KB
testcase_43 AC 327 ms
89,356 KB
testcase_44 AC 359 ms
89,356 KB
testcase_45 AC 332 ms
89,484 KB
testcase_46 AC 338 ms
89,484 KB
testcase_47 AC 351 ms
89,484 KB
testcase_48 AC 352 ms
89,484 KB
testcase_49 AC 342 ms
89,356 KB
testcase_50 AC 355 ms
89,484 KB
testcase_51 AC 346 ms
89,356 KB
testcase_52 AC 350 ms
89,356 KB
testcase_53 AC 354 ms
89,356 KB
testcase_54 AC 210 ms
89,356 KB
testcase_55 AC 216 ms
89,356 KB
testcase_56 AC 143 ms
87,692 KB
testcase_57 AC 143 ms
87,692 KB
testcase_58 AC 139 ms
87,692 KB
testcase_59 AC 142 ms
87,692 KB
testcase_60 AC 144 ms
87,692 KB
testcase_61 AC 135 ms
87,692 KB
testcase_62 AC 134 ms
87,692 KB
testcase_63 AC 137 ms
87,692 KB
testcase_64 AC 134 ms
87,692 KB
testcase_65 AC 137 ms
87,692 KB
testcase_66 AC 206 ms
89,356 KB
testcase_67 AC 135 ms
87,692 KB
testcase_68 AC 232 ms
89,356 KB
testcase_69 AC 138 ms
87,692 KB
testcase_70 AC 214 ms
89,356 KB
testcase_71 AC 138 ms
87,692 KB
testcase_72 AC 132 ms
87,692 KB
testcase_73 AC 133 ms
87,692 KB
testcase_74 AC 135 ms
87,692 KB
testcase_75 AC 140 ms
87,692 KB
testcase_76 AC 132 ms
87,692 KB
testcase_77 AC 142 ms
87,692 KB
testcase_78 AC 141 ms
87,692 KB
testcase_79 AC 143 ms
87,692 KB
testcase_80 AC 222 ms
89,356 KB
testcase_81 AC 145 ms
87,692 KB
testcase_82 AC 222 ms
89,356 KB
testcase_83 AC 137 ms
87,692 KB
testcase_84 AC 141 ms
87,692 KB
testcase_85 AC 138 ms
87,692 KB
testcase_86 AC 191 ms
89,356 KB
testcase_87 AC 138 ms
87,692 KB
権限があれば一括ダウンロードができます

ソースコード

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