結果
| 問題 |
No.1286 Stone Skipping
|
| コンテスト | |
| ユーザー |
vtr_coder
|
| 提出日時 | 2020-11-13 23:55:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,498 bytes |
| コンパイル時間 | 1,583 ms |
| コンパイル使用メモリ | 166,780 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-23 09:55:18 |
| 合計ジャッジ時間 | 2,321 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#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;
}
return false;
}
int GetDist(int x, int k) {
int cur = 0;
REP(i, k) {
cur += x;
x /= 2;
}
return cur;
}
signed main() {
IOS;
cin >> D;
// x 回はねたことにする
int ans = LLINF;
for(int x = 0; x < 63; ++x) {
int lb = 0, ub = D;
while(ub - lb > 1) {
int mid = (ub + lb) / 2;
int val = GetDist(mid, x);
if(val == D) {
chmin(ans, mid);
ub = mid;
}
else if(val < D) {
lb = mid;
}
else {
ub = mid;
}
}
if(Check(lb)) { chmin(ans, lb); }
if(Check(ub)) { chmin(ans, ub); }
}
print(ans);
return 0;
}
vtr_coder