結果
問題 | No.2594 Mix shake!! |
ユーザー |
👑 ![]() |
提出日時 | 2023-12-22 06:31:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 175 ms / 2,000 ms |
コード長 | 2,957 bytes |
コンパイル時間 | 383 ms |
コンパイル使用メモリ | 82,852 KB |
実行使用メモリ | 76,480 KB |
最終ジャッジ日時 | 2024-09-27 11:17:47 |
合計ジャッジ時間 | 8,804 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 85 |
ソースコード
import mathdef cmp_fracs(a, b) :return a[0] * b[1] < a[1] * b[0]def add_frac(a, b) :return [ a[0] * b[1] + a[1] * b[0], a[1] * b[1] ]def sub_frac(a, b) :return [ a[0] * b[1] - a[1] * b[0], a[1] * b[1] ]def mul_frac(a, b) :return [ a[0] * b[0], a[1] * b[1] ]def div_frac(a, b) :return [ a[0] * b[1], a[1] * b[0] ]def refine_frac(a) :g = math.gcd(a[0], a[1])return [ a[0] // g, a[1] // g ]ZERO_FRAC = [0,1]def verify2(a : list[list[int]], b : list[list[int]], max_t : int) :a2 = [[ZERO_FRAC,ZERO_FRAC]]for x in a :a2.append([ add_frac(a2[-1][0], [x[0],1]), add_frac(a2[-1][1], [x[1],1]) ])b2 = [[ZERO_FRAC,ZERO_FRAC]]for x in b :b2.append([ add_frac(b2[-1][0], [x[0],1]), add_frac(b2[-1][1], [x[1],1]) ])px = ZERO_FRACpy = ZERO_FRACt = 0while cmp_fracs(px, b2[-1][0]) :t += 1if t > max_t :return Falsemin_slope = [1,0]for bp in b2 :if not cmp_fracs(px, bp[0]) : continuedx = sub_frac(bp[0], px)dy = sub_frac(bp[1], py)slope = div_frac(dy, dx)if cmp_fracs(slope, min_slope) :min_slope = slopemin_slope = refine_frac(min_slope)found = 0for ap0,ap1 in zip(a2[:-1],a2[1:]) :if not cmp_fracs(px, ap1[0]) : continuea1xf = sub_frac(ap1[0], px)a1yf = sub_frac(ap1[1], py)slope = div_frac(a1yf, a1xf)if not cmp_fracs(min_slope, slope) : continuea1yf = sub_frac(a1yf, mul_frac(a1xf, min_slope))dxa = sub_frac(ap1[0],ap0[0])dya = sub_frac(ap1[1],ap0[1])aslope = sub_frac(div_frac(dya, dxa), min_slope)crossx = sub_frac(ap1[0], div_frac(a1yf, aslope))crossy = add_frac(py, mul_frac(min_slope, sub_frac(crossx, px)))px = refine_frac(crossx)py = refine_frac(crossy)found = 1breakif found == 0 :breakreturn Truedef input_positions(n) :ax = list(map(int,input().split()))ay = list(map(int,input().split()))return [ [ax[i],ay[i]] for i in range(n) ]def get_arg_order(a : list[list[int]]) :a = [[x[0],x[1]] for x in a]res = [i for i in range(len(a))]for i in range(n) :for j in range(n-1) :if a[j][0] * a[j+1][1] < a[j][1] * a[j+1][0] :res[j], res[j+1] = res[j+1], res[j]a[j], a[j+1] = a[j+1], a[j]return resn = int(input())a = input_positions(n)b = input_positions(n)a_ord = get_arg_order(a)b_ord = get_arg_order(b)a_sorted = [a[i] for i in a_ord]b_sorted = [b[i] for i in b_ord]a_model = [a[i] for i in b_ord]b_model = [b[i] for i in b_ord]if verify2(a_model, b_model, n) :print("Yes")exit()if verify2(a_sorted, b_sorted, n-1) :print("Yes")exit()print("No")