結果

問題 No.1651 Removing Cards
ユーザー 👑 KazunKazun
提出日時 2021-08-20 22:25:17
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,050 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 83,840 KB
最終ジャッジ日時 2024-04-22 05:09:38
合計ジャッジ時間 5,142 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
57,600 KB
testcase_01 AC 39 ms
52,224 KB
testcase_02 AC 187 ms
58,112 KB
testcase_03 AC 49 ms
58,880 KB
testcase_04 AC 46 ms
59,392 KB
testcase_05 AC 43 ms
58,752 KB
testcase_06 AC 45 ms
59,392 KB
testcase_07 AC 43 ms
58,880 KB
testcase_08 AC 48 ms
59,776 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def General_Binary_Increase_Search_Integer(L,R,cond,default=None):
    """条件式が単調増加であるとき, 整数上で二部探索を行う.
    L: 解の下限
    R: 解の上限
    cond: 条件(1変数関数, 広義単調増加を満たす)
    default: Lで条件を満たさないときの返り値
    """
    if not(cond(R)): return default

    if cond(L): return L

    R+=1
    while R-L>1:
        C=L+(R-L)//2
        if cond(C): R=C
        else: L=C
    return R
#==================================================
def count(K,M):
    X=0
    while M>1:
        R=(M+(K-1))//K
        S=(K+M+R-K*R-1)//R

        X+=S
        M-=R*S

        if M==0:
            M+=1
            X-=1
    return X
#==================================================
import sys
input=sys.stdin.readline
write=sys.stdout.write

K,Q=map(int,input().split())

Ans=[]
for _ in range(Q):
    N=int(input())
    alpha=count(K,N)

    Ans.append(General_Binary_Increase_Search_Integer(1,N,lambda m:count(K,m)>=alpha))

write("\n".join(map(str,Ans)))
0