結果

問題 No.195 フィボナッチ数列の理解(2)
ユーザー shotoyooshotoyoo
提出日時 2021-06-28 23:07:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,878 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 11,128 KB
実行使用メモリ 30,160 KB
最終ジャッジ日時 2023-09-08 00:05:01
合計ジャッジ時間 4,792 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
29,668 KB
testcase_01 AC 129 ms
29,668 KB
testcase_02 AC 142 ms
30,024 KB
testcase_03 AC 130 ms
29,756 KB
testcase_04 AC 142 ms
29,892 KB
testcase_05 AC 128 ms
29,672 KB
testcase_06 AC 128 ms
29,684 KB
testcase_07 AC 129 ms
29,780 KB
testcase_08 AC 130 ms
29,668 KB
testcase_09 AC 128 ms
29,772 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 140 ms
29,912 KB
testcase_17 WA -
testcase_18 AC 141 ms
29,976 KB
testcase_19 AC 142 ms
29,960 KB
testcase_20 AC 143 ms
29,964 KB
testcase_21 WA -
testcase_22 AC 143 ms
29,948 KB
testcase_23 AC 142 ms
29,948 KB
testcase_24 AC 143 ms
29,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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))

import numpy as np
x,y,z = list(map(int, input().split()))
f = [1,1]
for i in range(31):
    f.append(f[-2]+f[-1])
s = set([x,y,z])
ans = None
if len(s)==1:
    a = 1
    for i in range(30)[::-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(30):
        for j in range(30):
            if i==j:
                continue
            v1,v2 = np.linalg.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:
        ans = (-1,)
else:
    x,y,z = s
    ans = None
    for i in range(30):
        for j in range(30):
            if i==j:
                continue
            v1,v2 = np.linalg.solve([[f[i], f[i+1]], [f[j], f[j+1]]], [x,y])
            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(30):
                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)
0