結果
| 問題 |
No.195 フィボナッチ数列の理解(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-28 23:05:43 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,828 bytes |
| コンパイル時間 | 301 ms |
| コンパイル使用メモリ | 13,056 KB |
| 実行使用メモリ | 45,132 KB |
| 最終ジャッジ日時 | 2024-06-25 17:20:58 |
| 合計ジャッジ時間 | 14,417 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 8 |
ソースコード
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
for k in range(30):
if abs(f[k]*v1 + f[k+1]*v2 - z) < 1e-7:
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)