結果
問題 | No.195 フィボナッチ数列の理解(2) |
ユーザー | shotoyoo |
提出日時 | 2021-06-28 23:28:08 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 938 ms / 5,000 ms |
コード長 | 2,452 bytes |
コンパイル時間 | 204 ms |
コンパイル使用メモリ | 13,184 KB |
実行使用メモリ | 54,444 KB |
最終ジャッジ日時 | 2024-06-25 17:21:45 |
合計ジャッジ時間 | 26,320 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
外部呼び出し有り |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 920 ms
54,052 KB |
testcase_01 | AC | 933 ms
54,432 KB |
testcase_02 | AC | 925 ms
54,316 KB |
testcase_03 | AC | 932 ms
54,056 KB |
testcase_04 | AC | 915 ms
53,924 KB |
testcase_05 | AC | 910 ms
53,800 KB |
testcase_06 | AC | 919 ms
54,436 KB |
testcase_07 | AC | 922 ms
54,444 KB |
testcase_08 | AC | 925 ms
54,284 KB |
testcase_09 | AC | 910 ms
54,156 KB |
testcase_10 | AC | 923 ms
53,796 KB |
testcase_11 | AC | 932 ms
54,056 KB |
testcase_12 | AC | 922 ms
54,436 KB |
testcase_13 | AC | 916 ms
54,188 KB |
testcase_14 | AC | 922 ms
53,924 KB |
testcase_15 | AC | 922 ms
53,796 KB |
testcase_16 | AC | 925 ms
54,316 KB |
testcase_17 | AC | 927 ms
54,152 KB |
testcase_18 | AC | 933 ms
54,312 KB |
testcase_19 | AC | 932 ms
54,328 KB |
testcase_20 | AC | 936 ms
53,928 KB |
testcase_21 | AC | 934 ms
53,960 KB |
testcase_22 | AC | 933 ms
54,060 KB |
testcase_23 | AC | 938 ms
54,060 KB |
testcase_24 | AC | 934 ms
54,184 KB |
ソースコード
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") writef = lambda x: print("{:.12f}".format(x)) def solve(a,b,c,d,e,f): """ ax + by + c = 0 dx + ey + f = 0 """ v = (a*e-b*d) if v==0: # 縮退している if b!=0: return (0, -c/b) else: return (-c/a,0) x = - (c*e - f*b) / v y = (d*c - a*f) / v return (x,y) def solve(A,B): (a,b),(c,d) = A v = a*d-b*c assert v!=0 return (d*B[0]-b*B[1])/v, (-c*B[0]+a*B[1])/v import scipy.linalg import numpy as np x,y,z = list(map(int, input().split())) f = [1,0] for i in range(301): f.append(f[-2]+f[-1]) s = set([x,y,z]) ans = None if len(s)==1: a = 1 for i in range(50)[::-1]: if (x - f[i]) % f[i+1] == 0 and (x-f[i])//f[i+1]>0: b = (x-f[i])//f[i+1] ans = (a,b) break else: if x==1: ans = (1,1) else: ans = (1, x-1) elif len(s)==2: x,y = s ans = None for i in range(50): for j in range(50): if i==j: continue v1,v2 = solve(([[f[i], f[i+1]], [f[j], f[j+1]]]), ([x,y])) v1,v2 = int(v1+0.1), int(v2+0.1) if not (f[i]*v1 + f[i+1]*v2 == x and f[j]*v1 + f[j+1]*v2==y): continue if v1>0 and v2>0 and (ans is None or (v1,v2)<ans): ans = (v1,v2) if ans is None: aa = min(x,y) bb = max(x,y) ans = min((aa,bb), (bb-aa, aa), (aa, bb-aa)) else: x,y,z = s ans = None for i in range(50): for j in range(50): if i==j: continue try: v1,v2 = solve(([[f[i], f[i+1]], [f[j], f[j+1]]]), ([x,y])) except Exception: continue v1 = int(v1+0.1) v2 = int(v2+0.1) if not (f[i]*v1 + f[i+1]*v2 == x and f[j]*v1 + f[j+1]*v2==y): continue if not (v1>0 and v2>0): continue for k in range(50): if f[k]*v1 + f[k+1]*v2 == z: if v1>0 and v2>0: if (ans is None or (v1,v2)<ans): ans = (int(v1+0.1), int(v2+0.1)) if ans is None: ans = (-1,) print(*ans)