結果
| 問題 |
No.680 作れる数
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2020-06-17 01:47:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 936 bytes |
| コンパイル時間 | 681 ms |
| コンパイル使用メモリ | 82,716 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-03 12:03:04 |
| 合計ジャッジ時間 | 1,575 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function 'int calc(int)':
main.cpp:25:13: warning: 'i' may be used uninitialized [-Wmaybe-uninitialized]
25 | int m = 1<<i;
| ^
main.cpp:24:13: note: 'i' was declared here
24 | for(int i = d; i >= 0; i--){
| ^
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int N;
int calc(int n){
int ans = 1;
int tmp = 1;
int d;
if(n == 1) return 1;
for(int i = 0; i <= 30; i++){
int m = 1<<i;
if(2*m > n) break;
d = i;
}
for(int i = d; i >= 0; i--){
int m = 1<<i;
if(m&n) tmp = tmp*2+1;
else tmp = tmp*2;
ans += tmp;
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
cin >> N;
if(N <= 1){
cout << "YES" << endl;
return 0;
}
int l = 1, r = N;
while(r-l > 1){
int c = (l+r)/2;
if(calc(c) > N) r = c;
else l = c;
}
if(calc(l) == N){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
}
milanis48663220