結果

問題 No.1286 Stone Skipping
ユーザー vineet jain
提出日時 2020-11-13 22:52:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 739 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 167,932 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-22 21:50:27
合計ジャッジ時間 2,492 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 calc(ll n){
  ll c=0;
  while(n>1) n/=2,c++;
  return c;
}
void solve(){
  ll d;
  cin>>d;
  ll init=d,mx=calc(d),ans=(1LL<<(mx-1LL));
  d-=((1LL<<mx) -1LL);

  if(d<=0){ cout<<ans<<endl;return; }
  ll res=1LL<<62;
  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));
  }
  if(d>0) ans=init;
  cout<<min(res,ans)<<endl;
}
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
0