結果

問題 No.1651 Removing Cards
ユーザー rianoriano
提出日時 2021-08-20 23:15:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 486 ms / 2,000 ms
コード長 3,059 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 167,408 KB
実行使用メモリ 7,528 KB
最終ジャッジ日時 2024-04-22 07:36:06
合計ジャッジ時間 13,290 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 102 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 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 2 ms
5,376 KB
testcase_09 AC 164 ms
5,376 KB
testcase_10 AC 162 ms
5,376 KB
testcase_11 AC 157 ms
5,376 KB
testcase_12 AC 158 ms
5,376 KB
testcase_13 AC 161 ms
5,376 KB
testcase_14 AC 158 ms
5,376 KB
testcase_15 AC 482 ms
7,524 KB
testcase_16 AC 468 ms
7,396 KB
testcase_17 AC 473 ms
7,400 KB
testcase_18 AC 461 ms
7,524 KB
testcase_19 AC 460 ms
7,396 KB
testcase_20 AC 457 ms
7,396 KB
testcase_21 AC 464 ms
7,524 KB
testcase_22 AC 465 ms
7,524 KB
testcase_23 AC 157 ms
5,376 KB
testcase_24 AC 142 ms
5,376 KB
testcase_25 AC 459 ms
7,524 KB
testcase_26 AC 440 ms
7,500 KB
testcase_27 AC 479 ms
7,520 KB
testcase_28 AC 477 ms
7,524 KB
testcase_29 AC 483 ms
7,528 KB
testcase_30 AC 486 ms
7,524 KB
testcase_31 AC 479 ms
7,524 KB
testcase_32 AC 151 ms
5,376 KB
testcase_33 AC 153 ms
5,376 KB
testcase_34 AC 153 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Pr pair<ll,ll>
#define Tp tuple<int,int,int>
#define riano_ std::ios::sync_with_stdio(false);std::cin.tie(nullptr);typedef modint<mod> mint
using Graph = vector<vector<int>>;

const ll mod = 1000000007;
template<uint64_t mod>
struct modint{
    uint64_t val;
    constexpr modint(const int64_t val_=0) noexcept:val((val_%int64_t(mod)+int64_t(mod))%int64_t(mod)){}
    constexpr modint operator-() const noexcept{
        return modint(*this)=mod-val;
    }
    constexpr modint operator+(const modint rhs) const noexcept{
        return modint(*this)+=rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept{
        return modint(*this)-=rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept{
        return modint(*this)*=rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept{
        return modint(*this)/=rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept{
        val+=rhs.val;
        val-=((val>=mod)?mod:0);
        return (*this);
    }
    constexpr modint &operator-=(const modint rhs) noexcept{
        val+=((val<rhs.val)?mod:0);
        val-=rhs.val;
        return (*this);
    }
    constexpr modint &operator*=(const modint rhs) noexcept{
        val=val*rhs.val%mod;
        return (*this);
    }
    constexpr modint &operator/=(modint rhs) noexcept{
        uint64_t ex=mod-2;
        modint now=1;
        while(ex){
            now*=((ex&1)?rhs:1);
            rhs*=rhs,ex>>=1;
        }
        return (*this)*=now;
    }
    constexpr bool operator==(const modint rhs) noexcept{
        return val==rhs.val;
    }
    constexpr bool operator!=(const modint rhs) noexcept{
        return val!=rhs.val;
    }
    friend constexpr ostream &operator<<(ostream& os,const modint x) noexcept{
        return os<<(x.val);
    }
    friend constexpr istream &operator>>(istream& is,modint& x) noexcept{
        uint64_t t;
        is>>t,x=t;
        return is;
    }
};

int main() {
    riano_; //ll ans = 0;
    ll K,Q; cin >> K >> Q;
    vector<ll> cand;
    cand.push_back(K);
    ll n = K;
    while(n<=1000000000000000000){
        //解から二分探索 binary search
        //分かれ目の"r"側の値を求める
        ll l,r,ans;
        l = 2; r = 1000000000000000002; //初期値の代入
        while(l<r){
            ll c = (l+r)/2;
            //cの場合に検証
            ll nx = c-(c-1)/K-1;
            if(nx<n){//cが"l側"になる条件判定
                l = c+1;
            }
            else r = c;
        }
        ans = l;
        if(ans%K==1) ans--;
        cand.push_back(ans);
        n = ans;
    }
    // for(ll x:cand){
    //     cout << x << endl;
    // }
    rep(i,Q){
        ll N; cin >> N;
        if(N<=K){
            cout << N << endl;
        }
        else{
            ll j = upper_bound(cand.begin(),cand.end(),N) - cand.begin();
            cout << cand[j-1] << endl;
        }
    }
}
0