結果

問題 No.1651 Removing Cards
ユーザー milanis48663220milanis48663220
提出日時 2021-08-21 00:31:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,740 bytes
コンパイル時間 1,390 ms
コンパイル使用メモリ 121,924 KB
実行使用メモリ 7,652 KB
最終ジャッジ日時 2024-04-22 09:55:54
合計ジャッジ時間 8,819 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 6 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 155 ms
5,376 KB
testcase_10 AC 159 ms
5,376 KB
testcase_11 AC 159 ms
5,376 KB
testcase_12 AC 156 ms
5,376 KB
testcase_13 AC 158 ms
5,376 KB
testcase_14 AC 157 ms
5,376 KB
testcase_15 AC 189 ms
7,652 KB
testcase_16 AC 187 ms
7,524 KB
testcase_17 AC 188 ms
7,396 KB
testcase_18 AC 189 ms
7,480 KB
testcase_19 AC 187 ms
7,400 KB
testcase_20 AC 188 ms
7,396 KB
testcase_21 AC 190 ms
7,524 KB
testcase_22 AC 170 ms
7,396 KB
testcase_23 AC 160 ms
5,376 KB
testcase_24 AC 142 ms
5,376 KB
testcase_25 AC 168 ms
7,652 KB
testcase_26 AC 165 ms
7,528 KB
testcase_27 AC 186 ms
7,400 KB
testcase_28 AC 187 ms
7,652 KB
testcase_29 AC 191 ms
7,276 KB
testcase_30 AC 191 ms
7,652 KB
testcase_31 AC 190 ms
7,400 KB
testcase_32 AC 153 ms
5,376 KB
testcase_33 AC 153 ms
5,376 KB
testcase_34 AC 154 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

vector<int> as_base(int n, int k){
    vector<int> ans;
    while(n != 0) {
        ans.push_back(n%k);
        n /= k;
    }
    return ans;
}

// calc a//b 
template<typename T>
T ceil_div(T a, T b){
    return (a+b-1)/b;
}

const ll N_MAX = 1e18;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int k, q; cin >> k >> q;
    auto f = [&](ll x){
        return x-(x/k+1);
    };
    auto nx = [&](ll x) -> ll{
        if(x%(k-1) == 0){
            return x+(x/(k-1))+1;
        }else{
            return x+(ceil_div<ll>(x, k-1));
        }
    };
    vector<ll> x;
    x.push_back(0);
    while(true){
        ll y = nx(x.back());
        x.push_back(y);
        if(y > N_MAX) break;
    }
    // print_vector(x);
    while(q--){
        ll n; cin >> n; n--;
        auto p = upper_bound(x.begin(), x.end(), n);
        p--;
        cout << (*p)+1 << endl;  
    }
}
0