結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 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 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 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 2 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 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 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();
}
0