結果
問題 | No.680 作れる数 |
ユーザー |
|
提出日時 | 2019-05-17 01:52:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 699 bytes |
コンパイル時間 | 1,417 ms |
コンパイル使用メモリ | 167,052 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-17 05:45:30 |
合計ジャッジ時間 | 2,187 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include<bits/stdc++.h> using namespace std; int find_depth(int N){ int d = 1; while ((1 << d) - 1 <= N) ++d; return d - 1; } int calc_threshold(int t, int r){ return t * ((1 << r) - 1); } bool solve(int N){ if (N <= 1) return true; int D = find_depth(N); int t = 1; for (int d = 1; d < D; ++d){ N -= t; int left = 2 * t + 1; int threshold = calc_threshold(left, D - d); if (N == threshold) return true; if (N > threshold){ t = left; }else{ t = left - 1; } } return N == t; } int main(){ int N; cin >> N; cout << (solve(N) ? "YES" : "NO") << endl; return 0; }