Atcoderの第146回Beginners contestのC問題を解いてみたのですが、よくわかりませんでした。
問題はこちらです。
私のコードがこちらになります。
python
1def digit(x: int) -> int: 2 return len(str(x)) 3def price(A: int, B: int, n: int) -> int: 4 return A*n + B*digit(len(str(n))) 5 6A, B, X = map(int, input().split()) 7pr = 10**9 8pl = 0 9if B > X: 10 print(0) 11elif price(A, B, 10**9) < X: 12 print(10**9) 13else: 14 flag = 0 15 while pr != pl: 16 pc = (pl+pr)//2 17 if X > price(A, B, pc): 18 pl = pc+1 19 elif X < price(A, B, pc): 20 pr = pc-1 21 else: 22 flag = 1 23 if price(A, B, pl-1) < X < price(A, B, pr): 24 ans = pl - 1 25 if price(A, B, pl) < X < price(A, B, pr+1): 26 ans = pl 27 if flag == 1: 28 ans = pc 29 print(ans)
いくつかのテストサンプルでは通るのですが、誤答の出力もあるみたいです。こう改良した方がよい、ここが間違っている等のご指摘お願い致します。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。