結果
問題 |
No.1651 Removing Cards
|
ユーザー |
![]() |
提出日時 | 2025-05-14 12:47:24 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,169 bytes |
コンパイル時間 | 338 ms |
コンパイル使用メモリ | 82,380 KB |
実行使用メモリ | 281,512 KB |
最終ジャッジ日時 | 2025-05-14 12:48:24 |
合計ジャッジ時間 | 10,415 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 TLE * 1 -- * 19 |
ソースコード
import sys def main(): input = sys.stdin.read().split() idx = 0 K = int(input[idx]) idx += 1 Q = int(input[idx]) idx += 1 queries = [int(input[idx + i]) for i in range(Q)] for N in queries: if N == 1: print(1) continue steps = [] current = N while current > 1: steps.append(current) m = (current - 1 + K) // K current = current - m steps.append(1) steps.reverse() ans = 1 for n in steps[1:]: m = (n - 1 + K) // K p = ans if K == 1: original_pos = p + 1 else: threshold = (m - 1) * (K - 1) if p <= threshold: block_x = (p - 1) // (K - 1) pos_in_block = (p - 1) % (K - 1) + 1 original_pos = block_x * K + 1 + pos_in_block else: offset = p - threshold original_pos = (m - 1) * K + 1 + offset ans = original_pos print(ans) if __name__ == '__main__': main()