結果
| 問題 | 
                            No.1286 Stone Skipping
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-11-15 17:39:45 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 512 bytes | 
| コンパイル時間 | 1,674 ms | 
| コンパイル使用メモリ | 192,232 KB | 
| 最終ジャッジ日時 | 2025-01-16 00:59:37 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 26 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         lint d; scanf("%lld",&d);
      |                 ~~~~~^~~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
int main(){
	lint d; scanf("%lld",&d);
	auto dist=[](lint x,int n){
		lint res=0;
		rep(i,n+1) res+=x, x/=2;
		return res;
	};
	lint ans=d;
	rep(n,61){ // 跳ね返る回数
		lint lo=(1LL<<n)-1,hi=d;
		if(lo>hi) continue;
		while(hi-lo>1){
			lint mi=(lo+hi)/2;
			if(dist(mi,n)<d) lo=mi;
			else             hi=mi;
		}
		if(dist(hi,n)==d) ans=min(ans,hi);
	}
	printf("%lld\n",ans);
	return 0;
}