結果
| 問題 |
No.1286 Stone Skipping
|
| コンテスト | |
| ユーザー |
monnu
|
| 提出日時 | 2021-07-10 20:42:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 724 bytes |
| コンパイル時間 | 1,523 ms |
| コンパイル使用メモリ | 168,212 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 02:50:48 |
| 合計ジャッジ時間 | 2,616 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
//#define INF 1000000000
#define INF 1000000000000000000
int main(){
ll D;
cin>>D;
//cout<<(D+2)/2<<endl;
vector<ll> pow2(60);
vector<ll> sum(60);
for(int i=0;i<60;i++){
pow2[i]=1LL<<i;
sum[i]=(1LL<<(i+1))-1;
}
ll ans=D;
for(int i=0;i<60;i++){
ll d=D;
ll x=0;
ll cnt=d/sum[i];
d-=sum[i]*cnt;
x+=pow2[i]*cnt;
for(int j=i-1;j>=0;j--){
if(d>=sum[j]){
d-=sum[j];
x+=pow2[j];
}
}
if(d==0){
ans=min<ll>(ans,x);
}
}
cout<<ans<<endl;
}
monnu