結果
問題 | No.1651 Removing Cards |
ユーザー |
![]() |
提出日時 | 2021-08-27 00:23:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 246 ms / 2,000 ms |
コード長 | 681 bytes |
コンパイル時間 | 2,012 ms |
コンパイル使用メモリ | 197,236 KB |
最終ジャッジ日時 | 2025-01-24 02:10:39 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main(){ll K, Q;cin >> K >> Q;vector<ll> A = {0};auto next = [&](ll x) -> ll {ll ok = x + x / (K - 1), ng = (x + 1) + (x + K) / (K - 1);auto check = [&](ll y) -> bool {return y - (y + K - 1) / K <= x;};while(abs(ok - ng) > 1){ll cen = (ok + ng) / 2;(check(cen) ? ok : ng) = cen;}return ok;};while(A.back() <= (ll)1e18){A.push_back(next(A.back()));}while(Q--){ll N;cin >> N;cout << *--lower_bound(A.begin(), A.end(), N) + 1 << endl;}}