結果
| 問題 | No.648 お や す み |
| コンテスト | |
| ユーザー |
yukinon0808
|
| 提出日時 | 2018-02-09 23:14:13 |
| 言語 | C++11 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| + 388µs | |
| コード長 | 1,111 bytes |
| 記録 | |
| コンパイル時間 | 413 ms |
| コンパイル使用メモリ | 99,240 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-08-26 12:32:21 |
| 合計ジャッジ時間 | 3,370 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
}
yukinon0808