結果
問題 |
No.1651 Removing Cards
|
ユーザー |
![]() |
提出日時 | 2025-05-14 12:48:32 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,103 bytes |
コンパイル時間 | 351 ms |
コンパイル使用メモリ | 82,320 KB |
実行使用メモリ | 268,476 KB |
最終ジャッジ日時 | 2025-05-14 12:50:05 |
合計ジャッジ時間 | 8,308 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 TLE * 1 -- * 19 |
ソースコード
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()