結果

問題 No.1286 Stone Skipping
ユーザー vtr_codervtr_coder
提出日時 2020-11-13 23:36:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,520 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 168,804 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-30 04:20:21
合計ジャッジ時間 2,859 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(int i=(l);i<int(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(int i=(l);i>=int(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<62);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

const int MOD = 1000000007;

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MAX_N = 100010;

int D;

bool Check(int x) {
    int cur = 0;
    while(x > 0) {
        cur += x;
        //if(cur == D) { return true; }
        x /= 2;
    }
    if(cur == D) { return true; }
    return false;
}

signed main() {
    IOS;

    cin >> D;

    V<> j_min, j_max;

    j_min.pb(1);
    j_max.pb(1);
    while(j_max[j_max.size()-1] < LLINF) {
        j_min.pb(j_min[j_min.size()-1] * 2);
        j_max.pb(j_max[j_max.size()-1] * 2 + 1);
        if(j_max.size() > 1 && j_max[j_max.size()-1] <= j_max[j_max.size()-2]) {
            j_max.pop_back();
            j_min.pop_back();
            break;
        }
    }

    V<> sum_min(j_min.size()), sum_max(j_max.size());
    sum_min[0] = 1;
    sum_max[0] = 1;
    for(int i = 1; i < j_min.size(); ++i) {
        sum_min[i] = sum_min[i-1] + j_min[i];
        sum_max[i] = sum_max[i-1] + j_max[i];
    }

    // D が何回はねた時作れる可能性があるか
    int cnt = -1;
    REP(i, sum_min.size()) {
        if(sum_min[i] <= D && D <= sum_max[i]) {
            cnt = i;
            break;
        }
    }
    if(cnt == -1) {
        print(D);
        return 0;
    }

    for(int k = -1; k <= 1; ++k) {
        int lb = sum_min[cnt], ub = sum_max[cnt];
        if(cnt + k >= 0 && cnt + k <= sum_max.size() - 1) {
            lb = sum_min[cnt], ub = sum_max[cnt];
        }
        int cur = 1;
        REP(i, cnt) {
            int mid = (ub + lb) / 2;
            if(mid < D) {
                lb = mid;
                cur = cur * 2 + 1;
            }
            else {
                ub = mid;
                cur = cur * 2;
            }
        }

        // 最終 lb +-100 あたりに答えありそう
        for(int cand = cur - 10000; cand <= cur + 10000; ++cand) {
            if(cand <= 0 || cand > D) { continue; }
            if(Check(cand)) {
                print(cand);
                return 0;
            }
        }
    }

    print(D);

    return 0;
}
0