結果

問題 No.1286 Stone Skipping
ユーザー YamaKasa
提出日時 2020-11-14 16:48:53
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 762 bytes
コンパイル時間 1,460 ms
コンパイル使用メモリ 167,328 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 09:57:58
合計ジャッジ時間 2,349 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

ll dist(ll x, int k) {
    ll ret = 0;
    for (int i = 0; i < k; i++) {
        ret += x;
        x /= 2;
    }
    return ret;
}

int main() {
    ll D;
    cin >> D;
    ll best = D;
    for (int i = 1; i <= 64; i++) {
        ll l = 0;
        ll r = D;
        while (r - l > 1) {
            ll m = l + (r - l) / 2;
            if (dist(m, i) >= D) {
                r = m;
            } else {
                l = m;
            }
        }
        if (dist(r, i) == D) {
            chmin(best, r);
        }
    }
    cout << best << "\n";
    return 0;
}
0