結果

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

ソースコード

diff #

import sys

def main():
    input = sys.stdin.read().split()
    idx = 0
    K = int(input[idx])
    idx += 1
    Q = int(input[idx])
    idx += 1
    queries = list(map(int, input[idx:idx+Q]))
    
    for N in queries:
        if N == 1:
            print(1)
            continue
        
        path = []
        current = N
        while True:
            path.append(current)
            if current == 1:
                break
            s = (current - 1) // K + 1
            current -= s
        
        path.reverse()
        ans = 1
        for n in path[1:]:
            ans += (ans - 1) // (K - 1) + 1
        
        print(ans)

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