結果

問題 No.1651 Removing Cards
ユーザー qwewe
提出日時 2025-04-24 12:20:43
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,103 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 82,060 KB
実行使用メモリ 268,060 KB
最終ジャッジ日時 2025-04-24 12:21:34
合計ジャッジ時間 8,491 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 TLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    input = sys.stdin.read().split()
    ptr = 0
    K = int(input[ptr])
    ptr += 1
    Q = int(input[ptr])
    ptr += 1
    queries = [int(input[ptr + i]) for i in range(Q)]
    ptr += Q

    K_minus_1 = K - 1

    for N in queries:
        if N == 1:
            print(1)
            continue

        # Collect the sequence of m's
        list_m = []
        current_n = N
        while current_n > 1:
            m = (current_n + K - 1) // K
            list_m.append(m)
            current_n -= m

        # Reverse to process from the earliest step to latest
        list_m.reverse()
        x = 1

        for m in list_m:
            if K_minus_1 == 0:
                # K is 1, but according to problem statement K >=2
                pass  # This case is impossible as per constraints
            else:
                threshold = (m - 1) * K_minus_1
                if x <= threshold:
                    q = (x - 1) // K_minus_1
                    x += q + 1
                else:
                    x += m

        print(x)

if __name__ == "__main__":
    main()
0