結果

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
#define ll int128_t
#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;
}
ll cal2(ll idx){
  ll ans=1;
  while(idx--)ans*=2;
  return ans;
}
void solve(){
  ll d;
  cin>>d;
  ll init=d,mx=calc(d),ans=0;
  ll res=cal2(80);
  rrep(i,mx-1,0){
    if((d-cal2(i+1)+1) >0) {d-= (cal2(i+1)-1); ans+= cal2(i);}
    else if((d-cal2(i+1)+1) == 0) {d-= (cal2(i+1)-1); ans+=cal2(i); break;}
    else res=min(res,ans+cal2(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