結果
| 問題 |
No.1936 Rational Approximation
|
| コンテスト | |
| ユーザー |
👑 Kazun
|
| 提出日時 | 2022-05-13 22:02:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 691 bytes |
| コンパイル時間 | 318 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 62,720 KB |
| 最終ジャッジ日時 | 2024-07-22 01:50:11 |
| 合計ジャッジ時間 | 8,244 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 1 |
| other | AC * 2 TLE * 1 -- * 11 |
ソースコード
#参考元
#https://tjkendev.github.io/procon-library/python/math/stern-brocot-tree.html
def Stern_Brocot(p,q,n):
a,b,c,d=0,1,1,0
lu,ru=1,1
lx,ly,rx,ry=0,1,1,0
flag=1
while flag and (lu or ru):
flag=0
s=a+c; t=b+d
if t*p<s*q:
flag=1
c,d=s,t
if t<=n:
rx,ry=s,t
else:
lu=0
if t*p>s*q:
flag=1
a,b=s,t
if t<=n:
lx,ly=s,t
else:
ru=0
return lx,ly,rx,ry
#==================================================
P,Q=map(int,input().split())
a,b,c,d=Stern_Brocot(P,Q,Q)
print(a+b+c+d)
Kazun