結果
問題 | No.2287 ++ -- *=a /=a |
ユーザー |
![]() |
提出日時 | 2023-04-28 22:56:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 639 bytes |
コンパイル時間 | 306 ms |
コンパイル使用メモリ | 82,328 KB |
実行使用メモリ | 83,616 KB |
最終ジャッジ日時 | 2024-11-17 21:52:51 |
合計ジャッジ時間 | 8,030 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 1 WA * 26 |
ソースコード
from sys import stdin input=lambda :stdin.readline()[:-1] memo={} def calc(y,x,a): if y==0: return x if y in memo: return memo[y] ans=abs(y-x) tmpL,tmpR=y,y+1 res=0 while tmpL<x: tmpL*=a tmpR*=a res+=1 if tmpL<=x<tmpR: ans=min(ans,res) else: ans=min(ans,res+min(abs(tmpL-x),res+abs(tmpR-x))) y1=y//a if y1<y: res1=abs(y1*a-y)+calc(y1,x,a)+1 ans=min(ans,res1) y2=(y+a-1)//a if y2<y: res2=abs(y2*a-y)+calc(y2,x,a)+1 ans=min(ans,res2) memo[y]=ans return ans for _ in range(int(input())): memo.clear() x,y,a=map(int,input().split()) print(calc(y,x,a))