結果

問題 No.1651 Removing Cards
ユーザー mkawa2mkawa2
提出日時 2023-09-21 09:57:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 284 ms / 2,000 ms
コード長 1,164 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 87,796 KB
最終ジャッジ日時 2023-09-21 09:57:16
合計ジャッジ時間 13,895 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,468 KB
testcase_01 AC 68 ms
71,284 KB
testcase_02 AC 77 ms
75,908 KB
testcase_03 AC 67 ms
71,264 KB
testcase_04 AC 68 ms
71,564 KB
testcase_05 AC 67 ms
71,388 KB
testcase_06 AC 68 ms
71,356 KB
testcase_07 AC 67 ms
71,476 KB
testcase_08 AC 69 ms
71,260 KB
testcase_09 AC 255 ms
87,444 KB
testcase_10 AC 228 ms
87,604 KB
testcase_11 AC 232 ms
87,616 KB
testcase_12 AC 230 ms
87,388 KB
testcase_13 AC 254 ms
87,532 KB
testcase_14 AC 230 ms
87,532 KB
testcase_15 AC 253 ms
87,584 KB
testcase_16 AC 254 ms
85,352 KB
testcase_17 AC 276 ms
87,584 KB
testcase_18 AC 258 ms
86,048 KB
testcase_19 AC 255 ms
85,344 KB
testcase_20 AC 253 ms
87,288 KB
testcase_21 AC 284 ms
85,388 KB
testcase_22 AC 248 ms
86,264 KB
testcase_23 AC 229 ms
86,056 KB
testcase_24 AC 218 ms
86,884 KB
testcase_25 AC 242 ms
87,044 KB
testcase_26 AC 217 ms
87,120 KB
testcase_27 AC 251 ms
87,792 KB
testcase_28 AC 253 ms
87,796 KB
testcase_29 AC 262 ms
87,452 KB
testcase_30 AC 253 ms
87,484 KB
testcase_31 AC 256 ms
87,500 KB
testcase_32 AC 201 ms
87,260 KB
testcase_33 AC 210 ms
87,608 KB
testcase_34 AC 236 ms
87,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = -1-(-1 << 31)
# inf = -1-(-1 << 63)
# md = 10**9+7
md = 998244353

k,q=LI()
nqi=[]
for qi in range(q):
    n=II()
    nqi.append((n,qi))

nqi.sort(key=lambda x:-x[0])

def d_cnt(p):
    d1=p//(k-1)+1
    return d1,((k-1)*d1-p+d1-1)//d1

ans=[0]*q
p,s=0,1
while nqi:
    d1,c=d_cnt(p)
    d2,c2=d_cnt(s)
    if c2<c:c=c2
    while nqi and nqi[-1][0]<=s+c*d2:
        n,qi=nqi.pop()
        ans[qi]=p+(n-s+d2-1)//d2*d1+1
    p+=d1*c
    s+=d2*c

print(*ans,sep="\n")
0