結果

問題 No.1286 Stone Skipping
ユーザー vineet jainvineet jain
提出日時 2020-11-13 23:15:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,078 bytes
コンパイル時間 4,408 ms
コンパイル使用メモリ 381,620 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 04:14:04
合計ジャッジ時間 5,711 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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