結果

問題 No.1651 Removing Cards
ユーザー 👑 tatyamtatyam
提出日時 2021-08-27 00:23:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 681 bytes
コンパイル時間 2,114 ms
コンパイル使用メモリ 203,512 KB
実行使用メモリ 7,500 KB
最終ジャッジ日時 2024-04-29 17:43:06
合計ジャッジ時間 11,746 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 8 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 199 ms
5,376 KB
testcase_10 AC 195 ms
5,376 KB
testcase_11 AC 205 ms
5,376 KB
testcase_12 AC 198 ms
5,376 KB
testcase_13 AC 199 ms
5,376 KB
testcase_14 AC 200 ms
5,376 KB
testcase_15 AC 240 ms
7,496 KB
testcase_16 AC 232 ms
7,500 KB
testcase_17 AC 231 ms
7,500 KB
testcase_18 AC 229 ms
7,496 KB
testcase_19 AC 226 ms
7,500 KB
testcase_20 AC 227 ms
7,500 KB
testcase_21 AC 228 ms
7,500 KB
testcase_22 AC 233 ms
7,376 KB
testcase_23 AC 206 ms
5,376 KB
testcase_24 AC 167 ms
5,376 KB
testcase_25 AC 194 ms
7,496 KB
testcase_26 AC 186 ms
7,376 KB
testcase_27 AC 236 ms
7,372 KB
testcase_28 AC 238 ms
7,496 KB
testcase_29 AC 225 ms
7,500 KB
testcase_30 AC 221 ms
7,500 KB
testcase_31 AC 229 ms
7,372 KB
testcase_32 AC 186 ms
5,376 KB
testcase_33 AC 185 ms
5,376 KB
testcase_34 AC 180 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0