結果
問題 | No.2594 Mix shake!! |
ユーザー |
![]() |
提出日時 | 2023-12-20 12:17:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 191 ms / 2,000 ms |
コード長 | 2,024 bytes |
コンパイル時間 | 293 ms |
コンパイル使用メモリ | 82,856 KB |
実行使用メモリ | 89,348 KB |
最終ジャッジ日時 | 2024-09-27 09:46:45 |
合計ジャッジ時間 | 16,165 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 85 |
ソースコード
from fractions import Fractiondef to_slope(vec: list[tuple[Fraction, int, int, int]]) -> list[tuple[int, int]]:x, y = 0, 0ret: list[tuple[int, int]] = []for _, a, b, _ in vec:x += ay += bret.append((x, y))return retdef solve() -> bool: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()))AB = [(Fraction(b, a), a, b, i) for i, (a, b) in enumerate(zip(A, B))]CD = [(Fraction(d, c), c, d, i) for i, (c, d) in enumerate(zip(C, D))]AB.sort()CD.sort()lb_xys = to_slope(AB) # 初期状態の y = f(x) の折れ線ub_xys = to_slope(CD) # 所望の最終状態の y = f(x) の折れ線# 最終状態の折れ線が初期状態の折れ線の下側を通っていたら明らかに Nofor (x0, y0), (x1, y1) in zip([(0, 0)] + lb_xys[:-1], lb_xys, strict=True):for x, y in ub_xys:if (x1 - x0) * (y - y0) - (y1 - y0) * (x - x0) < 0:return False# 初期状態と最終状態で濃度の大小関係が一致していたら Yesif [i for _, _, _, i in AB] == [i for _, _, _, i in CD]:return True# n - 1 本以下の線分で (0, 0) から右上まで到達できたら Yesvx, vy = Fraction(0, 1), Fraction(0, 1) # 現在位置for i in range(n - 1):# (vx, vy) から出て (px, py) を通る直線を考えるpx, py = ub_xys[i]if px <= vx:return True# y = a1 x + b1a1 = (py - vy) / (px - vx)b1 = vy - a1 * vx# y = a2 x + b2ax, ay = lb_xys[i]bx, by = lb_xys[i + 1]a2 = Fraction(by - ay, bx - ax)b2 = ay - a2 * axif a1 >= a2:return Truevx = (b2 - b1) / (a1 - a2)vy = a1 * vx + b1if vx >= bx:return Truereturn Falseprint("Yes" if solve() else "No")