結果

問題 No.1286 Stone Skipping
ユーザー vineet jainvineet jain
提出日時 2020-11-13 22:52:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 739 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 163,976 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-30 03:51:46
合計ジャッジ時間 2,792 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 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,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 WA -
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 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 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

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