結果

問題 No.2177 Recurring ab
ユーザー 👑 KazunKazun
提出日時 2023-01-10 01:46:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 987 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 75,948 KB
最終ジャッジ日時 2023-08-23 02:13:20
合計ジャッジ時間 4,459 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
75,452 KB
testcase_01 AC 74 ms
71,428 KB
testcase_02 AC 79 ms
75,716 KB
testcase_03 AC 78 ms
75,724 KB
testcase_04 AC 78 ms
75,560 KB
testcase_05 AC 77 ms
75,704 KB
testcase_06 AC 78 ms
75,892 KB
testcase_07 AC 77 ms
75,736 KB
testcase_08 AC 79 ms
75,932 KB
testcase_09 AC 79 ms
75,520 KB
testcase_10 AC 78 ms
75,944 KB
testcase_11 AC 76 ms
75,456 KB
testcase_12 AC 77 ms
75,912 KB
testcase_13 AC 76 ms
75,640 KB
testcase_14 AC 79 ms
75,644 KB
testcase_15 AC 78 ms
75,828 KB
testcase_16 AC 79 ms
75,648 KB
testcase_17 AC 80 ms
75,892 KB
testcase_18 AC 82 ms
75,948 KB
testcase_19 AC 80 ms
75,864 KB
testcase_20 AC 79 ms
75,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def General_Binary_Decrease_Search_Integer(L, R, cond, default=None):
    """ 条件式が単調減少であるとき, 整数上で二部探索を行う.

    L: 解の下限
    R: 解の上限
    cond: 条件 (1変数関数, 広義単調減少 を満たす)
    default: R で条件を満たさないときの返り値
    """

    if not(cond(L)):
        return default

    if cond(R):
        return R

    L-=1
    while R-L>1:
        C=L+(R-L)//2
        if cond(C):
            L=C
        else:
            R=C
    return L

#==================================================
def solve():
    from itertools import product
    N=int(input())

    X=0

    for a,b in product(range(10), repeat=2):
        if a==b:
            continue

        check=lambda p:N*(a*p+b)>(p*p-1)
        p_max=General_Binary_Decrease_Search_Integer(max(a,b)+1, 10**9, check, 0)
        X+=max(p_max-max(a,b), 0)
    return X

#==================================================
print(solve())
0