結果
| 問題 |
No.1286 Stone Skipping
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-13 22:47:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 927 bytes |
| コンパイル時間 | 1,637 ms |
| コンパイル使用メモリ | 168,248 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-22 21:46:45 |
| 合計ジャッジ時間 | 2,571 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 WA * 6 |
ソースコード
#include <bits/stdc++.h>
#define ll long long
#define rep(i,x,n) for(ll i=x;i<n;i++)
#define rrep(i,x,n) for(ll i=x;i>=n;i--)
using namespace std;
ll mod=1000000007;
void solve(){
ll d;
cin>>d;
ll init=d;
ll mx=floor(log2(d));
// ll dp[mx][mx];
ll sum=0,ans=(1LL<<(mx-1LL));
d-=((1LL<<mx) -1LL);
// cout<<d<<endl;
// cout<<((1LL<<mx) -1LL)<<endl;
// cout<<d<<" "<<mx<<endl;
if(d<=0){
cout<<ans<<endl;return;
}
// cout<<d<<" "<<ans<<endl;
// vector<int> v1LL;
ll res=LLONG_MAX;
rrep(i,mx-2,0){
if(d-(1LL<<(i+1LL))+1LL >0) {d-= ((1LL<<(i+1LL))-1LL); ans+= (1LL<<i);}
else if(d-(1LL<<(i+1LL))+1LL == 0) {d-= ((1LL<<(i+1LL))-1LL); ans+=( 1LL<<i); break;}
else{
res=min(res,ans+(1LL<<i));
}
}
// cout<<d<<endl;
if(d>0) ans=min(init,res);
cout<<min(res,ans)<<endl;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}