結果
問題 | No.648 お や す み |
ユーザー |
![]() |
提出日時 | 2018-02-09 23:14:13 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,111 bytes |
コンパイル時間 | 676 ms |
コンパイル使用メモリ | 78,088 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-13 21:02:31 |
合計ジャッジ時間 | 2,737 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 84 |
ソースコード
#include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <list> #include <set> #include <map> #include <stack> #include <queue> #include <string> #include <utility> #include <algorithm> #include <functional> #include <deque> #define INF 1e9 #define MAX_T 2000000000 using namespace std; typedef long long ll; typedef pair<int,int> P; ll n; ll sheep(ll t) { return t * (t + 1) / 2; } ll my_binary_search(ll l, ll r) { if (r - l == 1) { ll num_l = sheep(l); ll num_r = sheep(r); if (num_l == n) return l; else if (num_r == n) return r; else return 0; } ll c = (l + r) / 2; ll num = sheep(c); if (num == n) { return c; } else if (num > n) { return my_binary_search(l, c); } else { return my_binary_search(c, r); } } int main() { cin >> n; ll l = 0, r = MAX_T; ll ans = my_binary_search(l, r); if (ans == 0) cout << "NO" << endl; else { cout << "YES" << endl << ans << endl; } return 0; }